aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core
diff options
context:
space:
mode:
authorGravatar Hauke Heibel <hauke.heibel@gmail.com>2009-10-29 19:56:58 +0100
committerGravatar Hauke Heibel <hauke.heibel@gmail.com>2009-10-29 19:56:58 +0100
commitc70a603e342e486f6c534f9fa3fc2c5d5f3aa7f8 (patch)
treeee54a7e25dff6c17c0a186f12aa80e285e4c8f9b /Eigen/src/Core
parente513cc75c4661d490ccb425068740458f3483961 (diff)
added mean() reduction
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r--Eigen/src/Core/MatrixBase.h3
-rw-r--r--Eigen/src/Core/Redux.h15
2 files changed, 15 insertions, 3 deletions
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