From 7fd8418b199cda8b7facb37fccbe871375c5b6d2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 19 Jun 2010 23:36:38 +0200 Subject: finish to merge Array into Core: - mv Array/* into Core/ - merge Functors.h files, and move Norms.h into Dot.h --- Eigen/src/Core/Dot.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'Eigen/src/Core/Dot.h') diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index dfa313e89..8eaa62185 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -80,6 +80,8 @@ MatrixBase::dot(const MatrixBase& other) const return ei_dot_nocheck::run(*this, other); } +//---------- implementation of L2 norm and related functions ---------- + /** \returns the squared \em l2 norm of *this, i.e., for vectors, the dot product of *this with itself. * * \sa dot(), norm() @@ -128,6 +130,61 @@ inline void MatrixBase::normalize() *this /= norm(); } +//---------- implementation of other norms ---------- + +template +struct ei_lpNorm_selector +{ + typedef typename NumTraits::Scalar>::Real RealScalar; + inline static RealScalar run(const MatrixBase& m) + { + return ei_pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p); + } +}; + +template +struct ei_lpNorm_selector +{ + inline static typename NumTraits::Scalar>::Real run(const MatrixBase& m) + { + return m.cwiseAbs().sum(); + } +}; + +template +struct ei_lpNorm_selector +{ + inline static typename NumTraits::Scalar>::Real run(const MatrixBase& m) + { + return m.norm(); + } +}; + +template +struct ei_lpNorm_selector +{ + inline static typename NumTraits::Scalar>::Real run(const MatrixBase& m) + { + return m.cwiseAbs().maxCoeff(); + } +}; + +/** \returns the \f$ \ell^p \f$ norm of *this, that is, returns the p-th root of the sum of the p-th powers of the absolute values + * of the coefficients of *this. If \a p is the special value \a Eigen::Infinity, this function returns the \f$ \ell^p\infty \f$ + * norm, that is the maximum of the absolute values of the coefficients of *this. + * + * \sa norm() + */ +template +template +inline typename NumTraits::Scalar>::Real +MatrixBase::lpNorm() const +{ + return ei_lpNorm_selector::run(*this); +} + +//---------- implementation of isOrthogonal / isUnitary ---------- + /** \returns true if *this is approximately orthogonal to \a other, * within the precision given by \a prec. * @@ -169,4 +226,5 @@ bool MatrixBase::isUnitary(RealScalar prec) const } return true; } + #endif // EIGEN_DOT_H -- cgit v1.2.3