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)))
{