added mean() reduction

This commit is contained in:
Hauke Heibel
2009-10-29 19:56:58 +01:00
parent e513cc75c4
commit c70a603e34
3 changed files with 23 additions and 3 deletions

View File

@@ -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;

View File

@@ -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