@@ -619,7 +619,7 @@ pub trait MutArrayView1<T: Debug + Display + Copy + Sized>:
619619 T : Number + PartialOrd ,
620620 {
621621 let stack_size = 64 ;
622- let mut jstack = -1 ;
622+ let mut jstack: i32 = -1 ;
623623 let mut l = 0 ;
624624 let mut istack = vec ! [ 0 ; stack_size] ;
625625 let mut ir = self . shape ( ) - 1 ;
@@ -2190,4 +2190,29 @@ mod tests {
21902190
21912191 assert_eq ! ( result, [ 65 , 581 , 30 ] )
21922192 }
2193+
2194+ #[ test]
2195+ fn test_argsort_mut_exact_boundary ( ) {
2196+ // Test index == length - 1 case
2197+ let boundary =
2198+ DenseMatrix :: from_2d_array ( & [ & [ 1.0 , 2.0 , 3.0 , f64:: MAX ] , & [ 3.0 , f64:: MAX , 0.0 , 2.0 ] ] )
2199+ . unwrap ( ) ;
2200+ let mut view0: Vec < f64 > = boundary. get_col ( 0 ) . iterator ( 0 ) . copied ( ) . collect ( ) ;
2201+ let indices = view0. argsort_mut ( ) ;
2202+ assert_eq ! ( indices. last( ) , Some ( & 1 ) ) ;
2203+ assert_eq ! ( indices. first( ) , Some ( & 0 ) ) ;
2204+
2205+ let mut view1: Vec < f64 > = boundary. get_col ( 3 ) . iterator ( 0 ) . copied ( ) . collect ( ) ;
2206+ let indices = view1. argsort_mut ( ) ;
2207+ assert_eq ! ( indices. last( ) , Some ( & 0 ) ) ;
2208+ assert_eq ! ( indices. first( ) , Some ( & 1 ) ) ;
2209+ }
2210+
2211+ #[ test]
2212+ fn test_argsort_mut_filled_array ( ) {
2213+ let matrix = DenseMatrix :: < f64 > :: rand ( 1000 , 1000 ) ;
2214+ let mut view: Vec < f64 > = matrix. get_col ( 0 ) . iterator ( 0 ) . copied ( ) . collect ( ) ;
2215+ let sorted = view. argsort_mut ( ) ;
2216+ assert_eq ! ( sorted. len( ) , 1000 ) ;
2217+ }
21932218}
0 commit comments