diff --git a/src/base/statistics.rs b/src/base/statistics.rs index 0fe18130..a6fadda6 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -1,5 +1,5 @@ use crate::{Scalar, Dim, Matrix, VectorN, RowVectorN, DefaultAllocator, U1, VectorSliceN}; -use alga::general::{Field, SupersetOf}; +use alga::general::{AdditiveMonoid, Field, SupersetOf}; use crate::storage::Storage; use crate::allocator::Allocator; @@ -54,7 +54,7 @@ impl> Matrix { } } -impl, R: Dim, C: Dim, S: Storage> Matrix { +impl> Matrix { /* * * Sum computation. @@ -83,11 +83,15 @@ impl, R: Dim, C: Dim, S: Storage> M /// # Example /// /// ``` - /// # use nalgebra::{Matrix2x3, RowVector3}; + /// # use nalgebra::{Matrix2x3, Matrix3x2}; + /// # use nalgebra::{RowVector2, RowVector3}; /// /// let m = Matrix2x3::new(1.0, 2.0, 3.0, /// 4.0, 5.0, 6.0); /// assert_eq!(m.row_sum(), RowVector3::new(5.0, 7.0, 9.0)); + /// + /// let mint = Matrix3x2::new(1,2,3,4,5,6); + /// assert_eq!(mint.row_sum(), RowVector2::new(9,12)); /// ``` #[inline] pub fn row_sum(&self) -> RowVectorN @@ -100,11 +104,15 @@ impl, R: Dim, C: Dim, S: Storage> M /// # Example /// /// ``` - /// # use nalgebra::{Matrix2x3, Vector3}; + /// # use nalgebra::{Matrix2x3, Matrix3x2}; + /// # use nalgebra::{Vector2, Vector3}; /// /// let m = Matrix2x3::new(1.0, 2.0, 3.0, /// 4.0, 5.0, 6.0); /// assert_eq!(m.row_sum_tr(), Vector3::new(5.0, 7.0, 9.0)); + /// + /// let mint = Matrix3x2::new(1,2,3,4,5,6); + /// assert_eq!(mint.row_sum_tr(), Vector2::new(9,12)); /// ``` #[inline] pub fn row_sum_tr(&self) -> VectorN @@ -117,21 +125,27 @@ impl, R: Dim, C: Dim, S: Storage> M /// # Example /// /// ``` - /// # use nalgebra::{Matrix2x3, Vector2}; + /// # use nalgebra::{Matrix2x3, Matrix3x2}; + /// # use nalgebra::{Vector2, Vector3}; /// /// let m = Matrix2x3::new(1.0, 2.0, 3.0, /// 4.0, 5.0, 6.0); /// assert_eq!(m.column_sum(), Vector2::new(6.0, 15.0)); + /// + /// let mint = Matrix3x2::new(1,2,3,4,5,6); + /// assert_eq!(mint.column_sum(), Vector3::new(3,7,11)); /// ``` #[inline] pub fn column_sum(&self) -> VectorN where DefaultAllocator: Allocator { let nrows = self.data.shape().0; self.compress_columns(VectorN::zeros_generic(nrows, U1), |out, col| { - out.axpy(N::one(), &col, N::one()) + *out += col; }) } +} +impl, R: Dim, C: Dim, S: Storage> Matrix { /* * * Variance computation.