norm2() renamed to squaredNorm(), kept as deprecated for now.

This commit is contained in:
Benoit Jacob 2008-11-03 19:14:17 +00:00
parent 3f580e240e
commit 3d90c13970
17 changed files with 51 additions and 36 deletions

View File

@ -207,8 +207,8 @@ template<typename ExpressionType, int Direction> class PartialRedux
* Example: \include PartialRedux_norm2.cpp
* Output: \verbinclude PartialRedux_norm2.out
*
* \sa MatrixBase::norm2() */
const typename ReturnType<ei_member_norm2>::Type norm2() const
* \sa MatrixBase::squaredNorm() */
const typename ReturnType<ei_member_norm2>::Type squaredNorm() const
{ return _expression(); }
/** \returns a row (or column) vector expression of the norm

View File

@ -93,7 +93,7 @@ void Cholesky<MatrixType>::compute(const MatrixType& a)
m_matrix.col(0).end(size-1) = a.row(0).end(size-1).adjoint() / ei_real(m_matrix.coeff(0,0));
for (int j = 1; j < size; ++j)
{
Scalar tmp = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).norm2();
Scalar tmp = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).squaredNorm();
x = ei_real(tmp);
if (x < eps || (!ei_isMuchSmallerThan(ei_imag(tmp), RealScalar(1))))
{

View File

@ -106,7 +106,7 @@ void LLT<MatrixType>::compute(const MatrixType& a)
m_matrix.col(0).end(size-1) = a.row(0).end(size-1).adjoint() / ei_real(m_matrix.coeff(0,0));
for (int j = 1; j < size; ++j)
{
Scalar tmp = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).norm2();
Scalar tmp = ei_real(a.coeff(j,j)) - m_matrix.row(j).start(j).squaredNorm();
x = ei_real(tmp);
if (x < eps || (!ei_isMuchSmallerThan(ei_imag(tmp), RealScalar(1))))
{

View File

@ -248,10 +248,10 @@ struct ei_dot_impl<Derived1, Derived2, LinearVectorization, CompleteUnrolling>
* \only_for_vectors
*
* \note If the scalar type is complex numbers, then this function returns the hermitian
* (sesquilinear) dot product, linear in the first variable and anti-linear in the
* (sesquilinear) dot product, linear in the first variable and conjugate-linear in the
* second variable.
*
* \sa norm2(), norm()
* \sa squaredNorm(), norm()
*/
template<typename Derived>
template<typename OtherDerived>
@ -275,6 +275,8 @@ MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
*
* \note This is \em not the \em l2 norm.
*
* \deprecated Use squaredNorm() instead. This norm2() function is kept only for compatibility and will be removed in Eigen 2.0.
*
* \only_for_vectors
*
* \sa dot(), norm()
@ -285,16 +287,28 @@ inline typename NumTraits<typename ei_traits<Derived>::Scalar>::Real MatrixBase<
return ei_real(dot(*this));
}
/** \returns the squared norm of *this, i.e. the dot product of *this with itself.
*
* \only_for_vectors
*
* \sa dot(), norm()
*/
template<typename Derived>
inline typename NumTraits<typename ei_traits<Derived>::Scalar>::Real MatrixBase<Derived>::squaredNorm() const
{
return ei_real(dot(*this));
}
/** \returns the \em l2 norm of *this, i.e. the square root of the dot product of *this with itself.
*
* \only_for_vectors
*
* \sa dot(), norm2()
* \sa dot(), normSquared()
*/
template<typename Derived>
inline typename NumTraits<typename ei_traits<Derived>::Scalar>::Real MatrixBase<Derived>::norm() const
{
return ei_sqrt(norm2());
return ei_sqrt(squaredNorm());
}
/** \returns an expression of the quotient of *this by its own norm.
@ -338,7 +352,7 @@ bool MatrixBase<Derived>::isOrthogonal
{
typename ei_nested<Derived,2>::type nested(derived());
typename ei_nested<OtherDerived,2>::type otherNested(other.derived());
return ei_abs2(nested.dot(otherNested)) <= prec * prec * nested.norm2() * otherNested.norm2();
return ei_abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm();
}
/** \returns true if *this is approximately an unitary matrix,
@ -358,7 +372,7 @@ bool MatrixBase<Derived>::isUnitary(RealScalar prec) const
typename Derived::Nested nested(derived());
for(int i = 0; i < cols(); i++)
{
if(!ei_isApprox(nested.col(i).norm2(), static_cast<Scalar>(1), prec))
if(!ei_isApprox(nested.col(i).squaredNorm(), static_cast<Scalar>(1), prec))
return false;
for(int j = 0; j < i; j++)
if(!ei_isMuchSmallerThan(nested.col(i).dot(nested.col(j)), static_cast<Scalar>(1), prec))

View File

@ -178,17 +178,17 @@ struct ei_fuzzy_selector<Derived,OtherDerived,true>
{
EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived);
ei_assert(self.size() == other.size());
return((self - other).norm2() <= std::min(self.norm2(), other.norm2()) * prec * prec);
return((self - other).squaredNorm() <= std::min(self.squaredNorm(), other.squaredNorm()) * prec * prec);
}
static bool isMuchSmallerThan(const Derived& self, const RealScalar& other, RealScalar prec)
{
return(self.norm2() <= ei_abs2(other * prec));
return(self.squaredNorm() <= ei_abs2(other * prec));
}
static bool isMuchSmallerThan(const Derived& self, const OtherDerived& other, RealScalar prec)
{
EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived);
ei_assert(self.size() == other.size());
return(self.norm2() <= other.norm2() * prec * prec);
return(self.squaredNorm() <= other.squaredNorm() * prec * prec);
}
};
@ -203,8 +203,8 @@ struct ei_fuzzy_selector<Derived,OtherDerived,false>
typename Derived::Nested nested(self);
typename OtherDerived::Nested otherNested(other);
for(int i = 0; i < self.cols(); i++)
if((nested.col(i) - otherNested.col(i)).norm2()
> std::min(nested.col(i).norm2(), otherNested.col(i).norm2()) * prec * prec)
if((nested.col(i) - otherNested.col(i)).squaredNorm()
> std::min(nested.col(i).squaredNorm(), otherNested.col(i).squaredNorm()) * prec * prec)
return false;
return true;
}
@ -212,7 +212,7 @@ struct ei_fuzzy_selector<Derived,OtherDerived,false>
{
typename Derived::Nested nested(self);
for(int i = 0; i < self.cols(); i++)
if(nested.col(i).norm2() > ei_abs2(other * prec))
if(nested.col(i).squaredNorm() > ei_abs2(other * prec))
return false;
return true;
}
@ -223,7 +223,7 @@ struct ei_fuzzy_selector<Derived,OtherDerived,false>
typename Derived::Nested nested(self);
typename OtherDerived::Nested otherNested(other);
for(int i = 0; i < self.cols(); i++)
if(nested.col(i).norm2() > otherNested.col(i).norm2() * prec * prec)
if(nested.col(i).squaredNorm() > otherNested.col(i).squaredNorm() * prec * prec)
return false;
return true;
}

View File

@ -330,6 +330,7 @@ template<typename Derived> class MatrixBase
template<typename OtherDerived>
Scalar dot(const MatrixBase<OtherDerived>& other) const;
RealScalar squaredNorm() const;
RealScalar norm2() const;
RealScalar norm() const;
const EvalType normalized() const;

View File

@ -171,7 +171,7 @@ typedef AngleAxis<double> AngleAxisd;
template<typename Scalar>
AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const QuaternionType& q)
{
Scalar n2 = q.vec().norm2();
Scalar n2 = q.vec().squaredNorm();
if (n2 < precision<Scalar>()*precision<Scalar>())
{
m_angle = 0;

View File

@ -88,7 +88,7 @@ public:
RealScalar squaredDistance(const VectorType& p) const
{
VectorType diff = p-origin();
return (diff - diff.dot(direction())* direction()).norm2();
return (diff - diff.dot(direction())* direction()).squaredNorm();
}
/** \returns the distance of a point \a p to its projection onto the line \c *this.
* \sa squaredDistance()

View File

@ -154,12 +154,12 @@ public:
inline Quaternion& setIdentity() { m_coeffs << 1, 0, 0, 0; return *this; }
/** \returns the squared norm of the quaternion's coefficients
* \sa Quaternion::norm(), MatrixBase::norm2()
* \sa Quaternion::norm(), MatrixBase::squaredNorm()
*/
inline Scalar norm2() const { return m_coeffs.norm2(); }
inline Scalar squaredNorm() const { return m_coeffs.squaredNorm(); }
/** \returns the norm of the quaternion's coefficients
* \sa Quaternion::norm2(), MatrixBase::norm()
* \sa Quaternion::squaredNorm(), MatrixBase::norm()
*/
inline Scalar norm() const { return m_coeffs.norm(); }
@ -374,7 +374,7 @@ template <typename Scalar>
inline Quaternion<Scalar> Quaternion<Scalar>::inverse() const
{
// FIXME should this function be called multiplicativeInverse and conjugate() be called inverse() or opposite() ??
Scalar n2 = this->norm2();
Scalar n2 = this->squaredNorm();
if (n2 > 0)
return Quaternion(conjugate().coeffs() / n2);
else

View File

@ -148,7 +148,7 @@ void HessenbergDecomposition<MatrixType>::_compute(MatrixType& matA, CoeffVector
// start of the householder transformation
// squared norm of the vector v skipping the first element
RealScalar v1norm2 = matA.col(i).end(n-(i+2)).norm2();
RealScalar v1norm2 = matA.col(i).end(n-(i+2)).squaredNorm();
if (ei_isMuchSmallerThan(v1norm2,static_cast<Scalar>(1)))
{

View File

@ -109,7 +109,7 @@ void QR<MatrixType>::_compute(const MatrixType& matrix)
m_hCoeffs.coeffRef(k) = 0;
}
}
else if ( (!ei_isMuchSmallerThan(beta=m_qr.col(k).end(remainingSize-1).norm2(),static_cast<Scalar>(1))) || ei_imag(v0)==0 )
else if ( (!ei_isMuchSmallerThan(beta=m_qr.col(k).end(remainingSize-1).squaredNorm(),static_cast<Scalar>(1))) || ei_imag(v0)==0 )
{
// form k-th Householder vector
beta = ei_sqrt(ei_abs2(v0)+beta);

View File

@ -198,7 +198,7 @@ void Tridiagonalization<MatrixType>::_compute(MatrixType& matA, CoeffVectorType&
// start of the householder transformation
// squared norm of the vector v skipping the first element
RealScalar v1norm2 = matA.col(i).end(n-(i+2)).norm2();
RealScalar v1norm2 = matA.col(i).end(n-(i+2)).squaredNorm();
if (ei_isMuchSmallerThan(v1norm2,static_cast<Scalar>(1)))
{

View File

@ -32,13 +32,13 @@ inline Scalar& at(uint i, uint j) { return this->operator()(i,j); }
inline Scalar at(uint i) const { return this->operator[](i); }
inline Scalar& at(uint i) { return this->operator[](i); }
inline RealScalar squaredLength() const { return norm2(); }
inline RealScalar squaredLength() const { return squaredNorm(); }
inline RealScalar length() const { return norm(); }
inline RealScalar invLength(void) const { return fast_inv_sqrt(norm2()); }
inline RealScalar invLength(void) const { return fast_inv_sqrt(squaredNorm()); }
template<typename OtherDerived>
inline Scalar squaredDistanceTo(const MatrixBase<OtherDerived>& other) const
{ return (derived() - other.derived()).norm2(); }
{ return (derived() - other.derived()).squaredNorm(); }
template<typename OtherDerived>
inline RealScalar distanceTo(const MatrixBase<OtherDerived>& other) const

View File

@ -352,7 +352,7 @@ vec3 = vec1.cross(vec2);\endcode</td></tr>
Eigen provides several reduction methods such as:
\link MatrixBase::minCoeff() minCoeff() \endlink, \link MatrixBase::maxCoeff() maxCoeff() \endlink,
\link MatrixBase::sum() sum() \endlink, \link MatrixBase::trace() trace() \endlink,
\link MatrixBase::norm() norm() \endlink, \link MatrixBase::norm2() norm2() \endlink,
\link MatrixBase::norm() norm() \endlink, \link MatrixBase::squaredNorm() squaredNorm() \endlink,
\link MatrixBase::all() all() \endlink,and \link MatrixBase::any() any() \endlink.
All reduction operations can be done matrix-wise,
\link MatrixBase::colwise() column-wise \endlink or
@ -473,8 +473,8 @@ mat3 = mat1.adjoint() * mat2;
</td></tr>
<tr><td>
\link MatrixBase::norm() norm \endlink of a vector \n
\link MatrixBase::norm2() squared norm \endlink of a vector
</td><td>\code vec.norm(); \endcode \n \code vec.norm2() \endcode
\link MatrixBase::squaredNorm() squared norm \endlink of a vector
</td><td>\code vec.norm(); \endcode \n \code vec.squaredNorm() \endcode
</td></tr>
<tr><td>
returns a \link MatrixBase::normalized() normalized \endlink vector \n

View File

@ -1,3 +1,3 @@
Matrix3d m = Matrix3d::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is the square norm of each row:" << endl << m.rowwise().norm2() << endl;
cout << "Here is the square norm of each row:" << endl << m.rowwise().squaredNorm() << endl;

View File

@ -68,9 +68,9 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
VERIFY(ei_isApprox((s1 * v1 + s2 * v2).dot(v3), s1 * v1.dot(v3) + s2 * v2.dot(v3), largerEps));
VERIFY(ei_isApprox(v3.dot(s1 * v1 + s2 * v2), ei_conj(s1)*v3.dot(v1)+ei_conj(s2)*v3.dot(v2), largerEps));
VERIFY_IS_APPROX(ei_conj(v1.dot(v2)), v2.dot(v1));
VERIFY_IS_APPROX(ei_abs(v1.dot(v1)), v1.norm2());
VERIFY_IS_APPROX(ei_abs(v1.dot(v1)), v1.squaredNorm());
if(NumTraits<Scalar>::HasFloatingPoint)
VERIFY_IS_APPROX(v1.norm2(), v1.norm() * v1.norm());
VERIFY_IS_APPROX(v1.squaredNorm(), v1.norm() * v1.norm());
VERIFY_IS_MUCH_SMALLER_THAN(ei_abs(vzero.dot(v1)), static_cast<RealScalar>(1));
if(NumTraits<Scalar>::HasFloatingPoint)
VERIFY_IS_MUCH_SMALLER_THAN(vzero.norm(), static_cast<RealScalar>(1));

View File

@ -78,7 +78,7 @@ template<typename Scalar> void geometry(void)
VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0);
VERIFY_IS_APPROX(-v0, AngleAxisx(M_PI, v0.unitOrthogonal()) * v0);
VERIFY_IS_APPROX(ei_cos(a)*v0.norm2(), v0.dot(AngleAxisx(a, v0.unitOrthogonal()) * v0));
VERIFY_IS_APPROX(ei_cos(a)*v0.squaredNorm(), v0.dot(AngleAxisx(a, v0.unitOrthogonal()) * v0));
m = AngleAxisx(a, v0.normalized()).toRotationMatrix().adjoint();
VERIFY_IS_APPROX(Matrix3::Identity(), m * AngleAxisx(a, v0.normalized()));
VERIFY_IS_APPROX(Matrix3::Identity(), AngleAxisx(a, v0.normalized()) * m);