diff options
author | Thomas Capricelli <orzel@freehackers.org> | 2009-11-26 02:28:13 +0100 |
---|---|---|
committer | Thomas Capricelli <orzel@freehackers.org> | 2009-11-26 02:28:13 +0100 |
commit | f795681da0fec9cd8a56f6987c903ec9a530d509 (patch) | |
tree | 7efa234cf98ea6f1a37756c488a5816c7e2e439a | |
parent | dca80b5f229cfb455a6beebbdaf2f6743beb71ed (diff) |
export stableNorm(), blueNorm() and hypotNorm() to colwise() and rowwise()
+ rudimentary test
-rw-r--r-- | Eigen/src/Array/VectorwiseOp.h | 30 | ||||
-rw-r--r-- | test/stable_norm.cpp | 8 |
2 files changed, 38 insertions, 0 deletions
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<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); EIGEN_MEMBER_FUNCTOR(norm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(stableNorm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(blueNorm, (Size+5) * NumTraits<Scalar>::MulCost + (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(hypotNorm, (Size-1) * ei_functor_traits<ei_scalar_hypot_op<Scalar> >::Cost ); EIGEN_MEMBER_FUNCTOR(sum, (Size-1)*NumTraits<Scalar>::AddCost); EIGEN_MEMBER_FUNCTOR(mean, (Size-1)*NumTraits<Scalar>::AddCost + NumTraits<Scalar>::MulCost); EIGEN_MEMBER_FUNCTOR(minCoeff, (Size-1)*NumTraits<Scalar>::AddCost); @@ -288,6 +291,33 @@ template<typename ExpressionType, int Direction> class VectorwiseOp const typename ReturnType<ei_member_norm>::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<ei_member_blueNorm>::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<ei_member_stableNorm>::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<ei_member_hypotNorm>::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<typename MatrixType> void stable_norm(const MatrixType& m) VERIFY_IS_APPROX(static_cast<Scalar>(vsmall.stableNorm()), ei_sqrt(size)*small); VERIFY_IS_APPROX(static_cast<Scalar>(vsmall.blueNorm()), ei_sqrt(size)*small); VERIFY_IS_APPROX(static_cast<Scalar>(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() |