@@ -72,8 +72,8 @@ impl<M: NumericOps + NumCast> MatrixNonZero for CscMatrix<M> {
7272}
7373
7474impl < M > MatrixSum for CscMatrix < M >
75- where
76- M : NumericOps + NumCast
75+ where
76+ M : NumericOps + NumCast ,
7777{
7878 type Item = M ;
7979
@@ -127,10 +127,10 @@ where
127127 }
128128}
129129
130- impl < M > MatrixVariance for CscMatrix < M >
131- where
130+ impl < M > MatrixVariance for CscMatrix < M >
131+ where
132132 CscMatrix < M > : MatrixSum + MatrixNonZero ,
133- M : NumericOps + NumCast
133+ M : NumericOps + NumCast ,
134134{
135135 type Item = M ;
136136
@@ -270,8 +270,8 @@ impl<M: NumCast + Copy + PartialOrd + NumericOps> MatrixMinMax for CscMatrix<M>
270270 where
271271 Item : num_traits:: NumCast + Copy + PartialOrd + NumericOps ,
272272 {
273- let mut min: Vec < Item > = vec ! [ Item :: min_value ( ) ; self . ncols( ) ] ;
274- let mut max: Vec < Item > = vec ! [ Item :: max_value ( ) ; self . ncols( ) ] ;
273+ let mut min: Vec < Item > = vec ! [ Item :: max_value ( ) ; self . ncols( ) ] ;
274+ let mut max: Vec < Item > = vec ! [ Item :: min_value ( ) ; self . ncols( ) ] ;
275275
276276 self . min_max_col_chunk ( ( & mut min, & mut max) ) ?;
277277 Ok ( ( min, max) )
@@ -281,8 +281,8 @@ impl<M: NumCast + Copy + PartialOrd + NumericOps> MatrixMinMax for CscMatrix<M>
281281 where
282282 Item : num_traits:: NumCast + Copy + PartialOrd + NumericOps ,
283283 {
284- let mut min: Vec < Item > = vec ! [ Item :: min_value ( ) ; self . nrows( ) ] ;
285- let mut max: Vec < Item > = vec ! [ Item :: max_value ( ) ; self . nrows( ) ] ;
284+ let mut min: Vec < Item > = vec ! [ Item :: max_value ( ) ; self . nrows( ) ] ;
285+ let mut max: Vec < Item > = vec ! [ Item :: min_value ( ) ; self . nrows( ) ] ;
286286
287287 self . min_max_row_chunk ( ( & mut min, & mut max) ) ?;
288288 Ok ( ( min, max) )
@@ -339,11 +339,10 @@ impl<M: NumCast + Copy + PartialOrd + NumericOps> MatrixMinMax for CscMatrix<M>
339339
340340 let col_offsets = self . col_offsets ( ) ;
341341 let row_indices = self . row_indices ( ) ;
342-
343342 let values = self . values ( ) ;
344343
345344 for col in 0 ..self . ncols ( ) {
346- let start_idx = row_indices [ col] ;
345+ let start_idx = col_offsets [ col] ;
347346 let end_idx = col_offsets[ col + 1 ] ;
348347
349348 for idx in start_idx..end_idx {
@@ -370,23 +369,25 @@ mod tests {
370369
371370 fn create_test_matrix ( ) -> CscMatrix < f64 > {
372371 use nalgebra_sparse:: CooMatrix ;
373-
372+
374373 // Create initial matrix with triplets for:
375374 // [1.0, 0.0, 2.0]
376375 // [0.0, 3.0, 0.0]
377376 // [4.0, 0.0, 5.0]
378377 let mut coo = CooMatrix :: try_from_triplets (
379- 3 , 3 ,
380- vec ! [ 0 , 2 ] , // row indices
381- vec ! [ 0 , 0 ] , // column indices
382- vec ! [ 1.0 , 4.0 ] // values
383- ) . unwrap ( ) ;
378+ 3 ,
379+ 3 ,
380+ vec ! [ 0 , 2 ] , // row indices
381+ vec ! [ 0 , 0 ] , // column indices
382+ vec ! [ 1.0 , 4.0 ] , // values
383+ )
384+ . unwrap ( ) ;
384385
385386 // Push remaining entries
386387 coo. push ( 1 , 1 , 3.0 ) ;
387388 coo. push ( 0 , 2 , 2.0 ) ;
388389 coo. push ( 2 , 2 , 5.0 ) ;
389-
390+
390391 // Convert to CscMatrix
391392 CscMatrix :: from ( & coo)
392393 }
@@ -550,5 +551,4 @@ mod tests {
550551 "All row minimums should be <= maximums"
551552 ) ;
552553 }
553-
554554}
0 commit comments