diff options
author | Hauke Heibel <hauke.heibel@gmail.com> | 2009-10-29 19:56:58 +0100 |
---|---|---|
committer | Hauke Heibel <hauke.heibel@gmail.com> | 2009-10-29 19:56:58 +0100 |
commit | c70a603e342e486f6c534f9fa3fc2c5d5f3aa7f8 (patch) | |
tree | ee54a7e25dff6c17c0a186f12aa80e285e4c8f9b /Eigen/src | |
parent | e513cc75c4661d490ccb425068740458f3483961 (diff) |
added mean() reduction
Diffstat (limited to 'Eigen/src')
-rw-r--r-- | Eigen/src/Array/VectorwiseOp.h | 8 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 3 | ||||
-rw-r--r-- | Eigen/src/Core/Redux.h | 15 |
3 files changed, 23 insertions, 3 deletions
diff --git a/Eigen/src/Array/VectorwiseOp.h b/Eigen/src/Array/VectorwiseOp.h index 4cb0083fa..6f6c2c8a7 100644 --- a/Eigen/src/Array/VectorwiseOp.h +++ b/Eigen/src/Array/VectorwiseOp.h @@ -122,6 +122,7 @@ 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(sum, (Size-1)*NumTraits<Scalar>::AddCost); +EIGEN_MEMBER_FUNCTOR(mean, (Size-1)*NumTraits<Scalar>::AddCost); EIGEN_MEMBER_FUNCTOR(minCoeff, (Size-1)*NumTraits<Scalar>::AddCost); EIGEN_MEMBER_FUNCTOR(maxCoeff, (Size-1)*NumTraits<Scalar>::AddCost); EIGEN_MEMBER_FUNCTOR(all, (Size-1)*NumTraits<Scalar>::AddCost); @@ -297,6 +298,13 @@ template<typename ExpressionType, int Direction> class VectorwiseOp const typename ReturnType<ei_member_sum>::Type sum() const { return _expression(); } + /** \returns a row (or column) vector expression of the mean + * of each column (or row) of the referenced expression. + * + * \sa MatrixBase::mean() */ + const typename ReturnType<ei_member_mean>::Type mean() const + { return _expression(); } + /** \returns a row (or column) vector expression representing * whether \b all coefficients of each respective column (or row) are \c true. * diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 2691fdecd..cb1589f85 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -645,8 +645,9 @@ template<typename Derived> class MatrixBase const CwiseBinaryOp<CustomBinaryOp, Derived, OtherDerived> binaryExpr(const MatrixBase<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const; - + Scalar sum() const; + Scalar mean() const; Scalar trace() const; Scalar prod() const; diff --git a/Eigen/src/Core/Redux.h b/Eigen/src/Core/Redux.h index 0df095750..9f796157a 100644 --- a/Eigen/src/Core/Redux.h +++ b/Eigen/src/Core/Redux.h @@ -342,7 +342,7 @@ MatrixBase<Derived>::maxCoeff() const /** \returns the sum of all coefficients of *this * - * \sa trace(), prod() + * \sa trace(), prod(), mean() */ template<typename Derived> EIGEN_STRONG_INLINE typename ei_traits<Derived>::Scalar @@ -351,12 +351,23 @@ MatrixBase<Derived>::sum() const return this->redux(Eigen::ei_scalar_sum_op<Scalar>()); } +/** \returns the mean of all coefficients of *this +* +* \sa trace(), prod(), sum() +*/ +template<typename Derived> +EIGEN_STRONG_INLINE typename ei_traits<Derived>::Scalar +MatrixBase<Derived>::mean() const +{ + return this->redux(Eigen::ei_scalar_sum_op<Scalar>()) / this->size(); +} + /** \returns the product of all coefficients of *this * * Example: \include MatrixBase_prod.cpp * Output: \verbinclude MatrixBase_prod.out * - * \sa sum() + * \sa sum(), mean(), trace() */ template<typename Derived> EIGEN_STRONG_INLINE typename ei_traits<Derived>::Scalar |