@@ -1105,7 +1105,7 @@ fn owned_array_with_stride() {
11051105
11061106#[ test]
11071107fn owned_array_discontiguous ( ) {
1108- use :: std:: iter:: repeat;
1108+ use std:: iter:: repeat;
11091109 let v: Vec < _ > = ( 0 ..12 ) . flat_map ( |x| repeat ( x) . take ( 2 ) ) . collect ( ) ;
11101110 let dim = ( 3 , 2 , 2 ) ;
11111111 let strides = ( 8 , 4 , 2 ) ;
@@ -1118,9 +1118,9 @@ fn owned_array_discontiguous() {
11181118
11191119#[ test]
11201120fn owned_array_discontiguous_drop ( ) {
1121- use :: std:: cell:: RefCell ;
1122- use :: std:: collections:: BTreeSet ;
1123- use :: std:: rc:: Rc ;
1121+ use std:: cell:: RefCell ;
1122+ use std:: collections:: BTreeSet ;
1123+ use std:: rc:: Rc ;
11241124
11251125 struct InsertOnDrop < T : Ord > ( Rc < RefCell < BTreeSet < T > > > , Option < T > ) ;
11261126 impl < T : Ord > Drop for InsertOnDrop < T > {
@@ -1959,6 +1959,48 @@ fn test_map_axis() {
19591959 itertools:: assert_equal ( result. iter ( ) . cloned ( ) . sorted ( ) , 1 ..=3 * 4 ) ;
19601960}
19611961
1962+ #[ test]
1963+ fn test_accumulate_axis_inplace_noop ( ) {
1964+ let mut a = Array2 :: < u8 > :: zeros ( ( 0 , 3 ) ) ;
1965+ a. accumulate_axis_inplace ( Axis ( 0 ) , |& prev, curr| * curr += prev) ;
1966+ assert_eq ! ( a, Array2 :: zeros( ( 0 , 3 ) ) ) ;
1967+
1968+ let mut a = Array2 :: < u8 > :: zeros ( ( 3 , 1 ) ) ;
1969+ a. accumulate_axis_inplace ( Axis ( 1 ) , |& prev, curr| * curr += prev) ;
1970+ assert_eq ! ( a, Array2 :: zeros( ( 3 , 1 ) ) ) ;
1971+ }
1972+
1973+ #[ rustfmt:: skip] // Allow block array formatting
1974+ #[ test]
1975+ fn test_accumulate_axis_inplace_nonstandard_layout ( ) {
1976+ let a = arr2 ( & [ [ 1 , 2 , 3 ] ,
1977+ [ 4 , 5 , 6 ] ,
1978+ [ 7 , 8 , 9 ] ,
1979+ [ 10 , 11 , 12 ] ] ) ;
1980+
1981+ let mut a_t = a. clone ( ) . reversed_axes ( ) ;
1982+ a_t. accumulate_axis_inplace ( Axis ( 0 ) , |& prev, curr| * curr += prev) ;
1983+ assert_eq ! ( a_t, aview2( & [ [ 1 , 4 , 7 , 10 ] ,
1984+ [ 3 , 9 , 15 , 21 ] ,
1985+ [ 6 , 15 , 24 , 33 ] ] ) ) ;
1986+
1987+ let mut a0 = a. clone ( ) ;
1988+ a0. invert_axis ( Axis ( 0 ) ) ;
1989+ a0. accumulate_axis_inplace ( Axis ( 0 ) , |& prev, curr| * curr += prev) ;
1990+ assert_eq ! ( a0, aview2( & [ [ 10 , 11 , 12 ] ,
1991+ [ 17 , 19 , 21 ] ,
1992+ [ 21 , 24 , 27 ] ,
1993+ [ 22 , 26 , 30 ] ] ) ) ;
1994+
1995+ let mut a1 = a. clone ( ) ;
1996+ a1. invert_axis ( Axis ( 1 ) ) ;
1997+ a1. accumulate_axis_inplace ( Axis ( 1 ) , |& prev, curr| * curr += prev) ;
1998+ assert_eq ! ( a1, aview2( & [ [ 3 , 5 , 6 ] ,
1999+ [ 6 , 11 , 15 ] ,
2000+ [ 9 , 17 , 24 ] ,
2001+ [ 12 , 23 , 33 ] ] ) ) ;
2002+ }
2003+
19622004#[ test]
19632005fn test_to_vec ( ) {
19642006 let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
0 commit comments