@@ -11,7 +11,9 @@ use approx::assert_relative_eq;
1111use defmac:: defmac;
1212use itertools:: { zip, Itertools } ;
1313use ndarray:: prelude:: * ;
14- use ndarray:: { arr3, indices, rcarr2, Slice , SliceInfo , SliceInfoElem } ;
14+ use ndarray:: { arr3, rcarr2} ;
15+ use ndarray:: indices;
16+ use ndarray:: { Slice , SliceInfo , SliceInfoElem } ;
1517use num_complex:: Complex ;
1618use std:: convert:: TryFrom ;
1719
@@ -2069,8 +2071,9 @@ fn test_view_from_shape_ptr() {
20692071#[ test]
20702072fn test_view_from_shape_ptr_deny_neg_strides ( ) {
20712073 let data = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
2072- let _view =
2073- unsafe { ArrayView :: from_shape_ptr ( ( 2 , 3 ) . strides ( ( -3isize as usize , 1 ) ) , data. as_ptr ( ) ) } ;
2074+ let _view = unsafe {
2075+ ArrayView :: from_shape_ptr ( ( 2 , 3 ) . strides ( ( -3isize as usize , 1 ) ) , data. as_ptr ( ) )
2076+ } ;
20742077}
20752078
20762079#[ should_panic( expected = "Unsupported" ) ]
@@ -2463,48 +2466,74 @@ mod array_cow_tests {
24632466
24642467#[ test]
24652468fn test_remove_index ( ) {
2466- let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
2469+ let mut a = arr2 ( & [ [ 1 , 2 , 3 ] ,
2470+ [ 4 , 5 , 6 ] ,
2471+ [ 7 , 8 , 9 ] ,
2472+ [ 10 , 11 , 12 ] ] ) ;
24672473 a. remove_index ( Axis ( 0 ) , 1 ) ;
24682474 a. remove_index ( Axis ( 1 ) , 2 ) ;
24692475 assert_eq ! ( a. shape( ) , & [ 3 , 2 ] ) ;
2470- assert_eq ! ( a, array![ [ 1 , 2 ] , [ 7 , 8 ] , [ 10 , 11 ] ] ) ;
2471-
2472- let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
2476+ assert_eq ! ( a,
2477+ array![ [ 1 , 2 ] ,
2478+ [ 7 , 8 ] ,
2479+ [ 10 , 11 ] ] ) ;
2480+
2481+ let mut a = arr2 ( & [ [ 1 , 2 , 3 ] ,
2482+ [ 4 , 5 , 6 ] ,
2483+ [ 7 , 8 , 9 ] ,
2484+ [ 10 , 11 , 12 ] ] ) ;
24732485 a. invert_axis ( Axis ( 0 ) ) ;
24742486 a. remove_index ( Axis ( 0 ) , 1 ) ;
24752487 a. remove_index ( Axis ( 1 ) , 2 ) ;
24762488 assert_eq ! ( a. shape( ) , & [ 3 , 2 ] ) ;
2477- assert_eq ! ( a, array![ [ 10 , 11 ] , [ 4 , 5 ] , [ 1 , 2 ] ] ) ;
2489+ assert_eq ! ( a,
2490+ array![ [ 10 , 11 ] ,
2491+ [ 4 , 5 ] ,
2492+ [ 1 , 2 ] ] ) ;
24782493
24792494 a. remove_index ( Axis ( 1 ) , 1 ) ;
24802495
24812496 assert_eq ! ( a. shape( ) , & [ 3 , 1 ] ) ;
2482- assert_eq ! ( a, array![ [ 10 ] , [ 4 ] , [ 1 ] ] ) ;
2497+ assert_eq ! ( a,
2498+ array![ [ 10 ] ,
2499+ [ 4 ] ,
2500+ [ 1 ] ] ) ;
24832501 a. remove_index ( Axis ( 1 ) , 0 ) ;
24842502 assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2485- assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
2503+ assert_eq ! ( a,
2504+ array![ [ ] ,
2505+ [ ] ,
2506+ [ ] ] ) ;
24862507}
24872508
2488- #[ should_panic( expected = "must be less" ) ]
2509+ #[ should_panic( expected= "must be less" ) ]
24892510#[ test]
24902511fn test_remove_index_oob1 ( ) {
2491- let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
2512+ let mut a = arr2 ( & [ [ 1 , 2 , 3 ] ,
2513+ [ 4 , 5 , 6 ] ,
2514+ [ 7 , 8 , 9 ] ,
2515+ [ 10 , 11 , 12 ] ] ) ;
24922516 a. remove_index ( Axis ( 0 ) , 4 ) ;
24932517}
24942518
2495- #[ should_panic( expected = "must be less" ) ]
2519+ #[ should_panic( expected= "must be less" ) ]
24962520#[ test]
24972521fn test_remove_index_oob2 ( ) {
24982522 let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
24992523 a. remove_index ( Axis ( 1 ) , 0 ) ;
25002524 assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2501- assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
2525+ assert_eq ! ( a,
2526+ array![ [ ] ,
2527+ [ ] ,
2528+ [ ] ] ) ;
25022529 a. remove_index ( Axis ( 0 ) , 1 ) ; // ok
2503- assert_eq ! ( a, array![ [ ] , [ ] ] ) ;
2530+ assert_eq ! ( a,
2531+ array![ [ ] ,
2532+ [ ] ] ) ;
25042533 a. remove_index ( Axis ( 1 ) , 0 ) ; // oob
25052534}
25062535
2507- #[ should_panic( expected = "index out of bounds" ) ]
2536+ #[ should_panic( expected= "index out of bounds" ) ]
25082537#[ test]
25092538fn test_remove_index_oob3 ( ) {
25102539 let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
@@ -2523,10 +2552,14 @@ fn test_split_complex_view() {
25232552
25242553#[ test]
25252554fn test_split_complex_view_roundtrip ( ) {
2526- let a_re = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( i, j, _k) | i * j) ;
2527- let a_im = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( _i, _j, k) | k) ;
2528- let a = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( i, j, k) | {
2529- Complex :: new ( a_re[ [ i, j, k] ] , a_im[ [ i, j, k] ] )
2555+ let a_re = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( i, j, _k) | {
2556+ i * j
2557+ } ) ;
2558+ let a_im = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( _i, _j, k) | {
2559+ k
2560+ } ) ;
2561+ let a = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( i, j, k) | {
2562+ Complex :: new ( a_re[ [ i, j, k] ] , a_im[ [ i, j, k] ] )
25302563 } ) ;
25312564 let Complex { re, im } = a. view ( ) . split_complex ( ) ;
25322565 assert_eq ! ( a_re, re) ;
@@ -2557,18 +2590,18 @@ fn test_split_complex_zerod() {
25572590
25582591#[ test]
25592592fn test_split_complex_permuted ( ) {
2560- let a = Array3 :: from_shape_fn ( ( 3 , 4 , 5 ) , |( i, j, k) | Complex :: new ( i * k + j, k) ) ;
2561- let permuted = a. view ( ) . permuted_axes ( [ 1 , 0 , 2 ] ) ;
2593+ let a = Array3 :: from_shape_fn ( ( 3 , 4 , 5 ) , |( i, j, k) | {
2594+ Complex :: new ( i * k + j, k)
2595+ } ) ;
2596+ let permuted = a. view ( ) . permuted_axes ( [ 1 , 0 , 2 ] ) ;
25622597 let Complex { re, im } = permuted. split_complex ( ) ;
2563- assert_eq ! ( re. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 11 ) ;
2564- assert_eq ! ( im. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 4 ) ;
2598+ assert_eq ! ( re. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 11 ) ;
2599+ assert_eq ! ( im. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 4 ) ;
25652600}
25662601
25672602#[ test]
25682603fn test_split_complex_invert_axis ( ) {
2569- let mut a = Array :: from_shape_fn ( ( 2 , 3 , 2 ) , |( i, j, k) | {
2570- Complex :: new ( i as f64 + j as f64 , i as f64 + k as f64 )
2571- } ) ;
2604+ let mut a = Array :: from_shape_fn ( ( 2 , 3 , 2 ) , |( i, j, k) | Complex :: new ( i as f64 + j as f64 , i as f64 + k as f64 ) ) ;
25722605 a. invert_axis ( Axis ( 1 ) ) ;
25732606 let cmplx = a. view ( ) . split_complex ( ) ;
25742607 assert_eq ! ( cmplx. re, a. mapv( |z| z. re) ) ;
0 commit comments