From f795681da0fec9cd8a56f6987c903ec9a530d509 Mon Sep 17 00:00:00 2001 From: Thomas Capricelli Date: Thu, 26 Nov 2009 02:28:13 +0100 Subject: export stableNorm(), blueNorm() and hypotNorm() to colwise() and rowwise() + rudimentary test --- Eigen/src/Array/VectorwiseOp.h | 30 ++++++++++++++++++++++++++++++ test/stable_norm.cpp | 8 ++++++++ 2 files changed, 38 insertions(+) diff --git a/Eigen/src/Array/VectorwiseOp.h b/Eigen/src/Array/VectorwiseOp.h index 880567212..7193e6f68 100644 --- a/Eigen/src/Array/VectorwiseOp.h +++ b/Eigen/src/Array/VectorwiseOp.h @@ -121,6 +121,9 @@ class PartialReduxExpr : ei_no_assignment_operator, EIGEN_MEMBER_FUNCTOR(squaredNorm, Size * NumTraits::MulCost + (Size-1)*NumTraits::AddCost); EIGEN_MEMBER_FUNCTOR(norm, (Size+5) * NumTraits::MulCost + (Size-1)*NumTraits::AddCost); +EIGEN_MEMBER_FUNCTOR(stableNorm, (Size+5) * NumTraits::MulCost + (Size-1)*NumTraits::AddCost); +EIGEN_MEMBER_FUNCTOR(blueNorm, (Size+5) * NumTraits::MulCost + (Size-1)*NumTraits::AddCost); +EIGEN_MEMBER_FUNCTOR(hypotNorm, (Size-1) * ei_functor_traits >::Cost ); EIGEN_MEMBER_FUNCTOR(sum, (Size-1)*NumTraits::AddCost); EIGEN_MEMBER_FUNCTOR(mean, (Size-1)*NumTraits::AddCost + NumTraits::MulCost); EIGEN_MEMBER_FUNCTOR(minCoeff, (Size-1)*NumTraits::AddCost); @@ -288,6 +291,33 @@ template class VectorwiseOp const typename ReturnType::Type norm() const { return _expression(); } + + /** \returns a row (or column) vector expression of the norm + * of each column (or row) of the referenced expression, using + * blue's algorithm. + * + * \sa MatrixBase::blueNorm() */ + const typename ReturnType::Type blueNorm() const + { return _expression(); } + + + /** \returns a row (or column) vector expression of the norm + * of each column (or row) of the referenced expression, avoiding + * underflow and overflow. + * + * \sa MatrixBase::stableNorm() */ + const typename ReturnType::Type stableNorm() const + { return _expression(); } + + + /** \returns a row (or column) vector expression of the norm + * of each column (or row) of the referenced expression, avoiding + * underflow and overflow using a concatenation of hypot() calls. + * + * \sa MatrixBase::hypotNorm() */ + const typename ReturnType::Type hypotNorm() const + { return _expression(); } + /** \returns a row (or column) vector expression of the sum * of each column (or row) of the referenced expression. * diff --git a/test/stable_norm.cpp b/test/stable_norm.cpp index 7661fc893..10531dc5d 100644 --- a/test/stable_norm.cpp +++ b/test/stable_norm.cpp @@ -79,6 +79,14 @@ template void stable_norm(const MatrixType& m) VERIFY_IS_APPROX(static_cast(vsmall.stableNorm()), ei_sqrt(size)*small); VERIFY_IS_APPROX(static_cast(vsmall.blueNorm()), ei_sqrt(size)*small); VERIFY_IS_APPROX(static_cast(vsmall.hypotNorm()), ei_sqrt(size)*small); + +// Test compilation of cwise() version + VERIFY_IS_APPROX(vrand.colwise().stableNorm(), vrand.colwise().norm()); + VERIFY_IS_APPROX(vrand.colwise().blueNorm(), vrand.colwise().norm()); + VERIFY_IS_APPROX(vrand.colwise().hypotNorm(), vrand.colwise().norm()); + VERIFY_IS_APPROX(vrand.rowwise().stableNorm(), vrand.rowwise().norm()); + VERIFY_IS_APPROX(vrand.rowwise().blueNorm(), vrand.rowwise().norm()); + VERIFY_IS_APPROX(vrand.rowwise().hypotNorm(), vrand.rowwise().norm()); } void test_stable_norm() -- cgit v1.2.3