diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-11-03 19:14:17 +0000 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2008-11-03 19:14:17 +0000 |
commit | 3d90c139706daccce577f5f2960ceb98a42871a3 (patch) | |
tree | f3c8c501a9d66e183a297b94a5b2362511e14161 | |
parent | 3f580e240e2a3018c7e040e4c4cfc9541c84166d (diff) |
norm2() renamed to squaredNorm(), kept as deprecated for now.
-rw-r--r-- | Eigen/src/Array/PartialRedux.h | 4 | ||||
-rw-r--r-- | Eigen/src/Cholesky/Cholesky.h | 2 | ||||
-rw-r--r-- | Eigen/src/Cholesky/LLT.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/Dot.h | 26 | ||||
-rw-r--r-- | Eigen/src/Core/Fuzzy.h | 14 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 1 | ||||
-rw-r--r-- | Eigen/src/Geometry/AngleAxis.h | 2 | ||||
-rw-r--r-- | Eigen/src/Geometry/ParametrizedLine.h | 2 | ||||
-rw-r--r-- | Eigen/src/Geometry/Quaternion.h | 8 | ||||
-rwxr-xr-x | Eigen/src/QR/HessenbergDecomposition.h | 2 | ||||
-rw-r--r-- | Eigen/src/QR/QR.h | 2 | ||||
-rwxr-xr-x | Eigen/src/QR/Tridiagonalization.h | 2 | ||||
-rw-r--r-- | doc/CustomizingEigen.dox | 6 | ||||
-rw-r--r-- | doc/QuickStartGuide.dox | 6 | ||||
-rw-r--r-- | doc/snippets/PartialRedux_norm2.cpp | 2 | ||||
-rw-r--r-- | test/adjoint.cpp | 4 | ||||
-rw-r--r-- | test/geometry.cpp | 2 |
17 files changed, 51 insertions, 36 deletions
diff --git a/Eigen/src/Array/PartialRedux.h b/Eigen/src/Array/PartialRedux.h index 357654b4e..ad3a8f3d7 100644 --- a/Eigen/src/Array/PartialRedux.h +++ b/Eigen/src/Array/PartialRedux.h @@ -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 diff --git a/Eigen/src/Cholesky/Cholesky.h b/Eigen/src/Cholesky/Cholesky.h index 5246d1f54..71549c43e 100644 --- a/Eigen/src/Cholesky/Cholesky.h +++ b/Eigen/src/Cholesky/Cholesky.h @@ -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)))) { diff --git a/Eigen/src/Cholesky/LLT.h b/Eigen/src/Cholesky/LLT.h index 16518b370..2fc658bb7 100644 --- a/Eigen/src/Cholesky/LLT.h +++ b/Eigen/src/Cholesky/LLT.h @@ -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)))) { diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index e9be929ce..6a1535787 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -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)) diff --git a/Eigen/src/Core/Fuzzy.h b/Eigen/src/Core/Fuzzy.h index b48c198b3..8fa1e1c26 100644 --- a/Eigen/src/Core/Fuzzy.h +++ b/Eigen/src/Core/Fuzzy.h @@ -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; } diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 8329ec148..1b07cba6b 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -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; diff --git a/Eigen/src/Geometry/AngleAxis.h b/Eigen/src/Geometry/AngleAxis.h index 37dee5c76..d5667190f 100644 --- a/Eigen/src/Geometry/AngleAxis.h +++ b/Eigen/src/Geometry/AngleAxis.h @@ -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; diff --git a/Eigen/src/Geometry/ParametrizedLine.h b/Eigen/src/Geometry/ParametrizedLine.h index 80ce72dcd..e726d2fe9 100644 --- a/Eigen/src/Geometry/ParametrizedLine.h +++ b/Eigen/src/Geometry/ParametrizedLine.h @@ -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() diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index 5b1b41d5e..ec79afa25 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -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 diff --git a/Eigen/src/QR/HessenbergDecomposition.h b/Eigen/src/QR/HessenbergDecomposition.h index 9f4865e1d..30541670c 100755 --- a/Eigen/src/QR/HessenbergDecomposition.h +++ b/Eigen/src/QR/HessenbergDecomposition.h @@ -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))) { diff --git a/Eigen/src/QR/QR.h b/Eigen/src/QR/QR.h index a6cd31f12..e584ee120 100644 --- a/Eigen/src/QR/QR.h +++ b/Eigen/src/QR/QR.h @@ -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); diff --git a/Eigen/src/QR/Tridiagonalization.h b/Eigen/src/QR/Tridiagonalization.h index 02d376c7a..a9635c961 100755 --- a/Eigen/src/QR/Tridiagonalization.h +++ b/Eigen/src/QR/Tridiagonalization.h @@ -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))) { diff --git a/doc/CustomizingEigen.dox b/doc/CustomizingEigen.dox index 9603c8076..f51c02e27 100644 --- a/doc/CustomizingEigen.dox +++ b/doc/CustomizingEigen.dox @@ -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 diff --git a/doc/QuickStartGuide.dox b/doc/QuickStartGuide.dox index 1d2f623b3..c46698dbf 100644 --- a/doc/QuickStartGuide.dox +++ b/doc/QuickStartGuide.dox @@ -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 diff --git a/doc/snippets/PartialRedux_norm2.cpp b/doc/snippets/PartialRedux_norm2.cpp index a077309a3..9f3293e65 100644 --- a/doc/snippets/PartialRedux_norm2.cpp +++ b/doc/snippets/PartialRedux_norm2.cpp @@ -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; diff --git a/test/adjoint.cpp b/test/adjoint.cpp index 18256a124..bf74b3f4f 100644 --- a/test/adjoint.cpp +++ b/test/adjoint.cpp @@ -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)); diff --git a/test/geometry.cpp b/test/geometry.cpp index 24904e264..b6899501c 100644 --- a/test/geometry.cpp +++ b/test/geometry.cpp @@ -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); |