99
1010use approx:: assert_relative_eq;
1111use defmac:: defmac;
12- use itertools:: { zip, Itertools } ;
12+ use itertools:: Itertools ;
13+ use ndarray:: indices;
1314use ndarray:: prelude:: * ;
1415use ndarray:: { arr3, rcarr2} ;
15- use ndarray:: indices;
1616use ndarray:: { Slice , SliceInfo , SliceInfoElem } ;
1717use num_complex:: Complex ;
1818use std:: convert:: TryFrom ;
@@ -499,13 +499,13 @@ fn test_index() {
499499 * elt = i;
500500 }
501501
502- for ( ( i, j) , a) in zip ( indices ( ( 2 , 3 ) ) , & A ) {
502+ for ( ( i, j) , a) in indices ( ( 2 , 3 ) ) . into_iter ( ) . zip ( & A ) {
503503 assert_eq ! ( * a, A [ [ i, j] ] ) ;
504504 }
505505
506506 let vi = A . slice ( s ! [ 1 .., ..; 2 ] ) ;
507507 let mut it = vi. iter ( ) ;
508- for ( ( i, j) , x) in zip ( indices ( ( 1 , 2 ) ) , & mut it) {
508+ for ( ( i, j) , x) in indices ( ( 1 , 2 ) ) . into_iter ( ) . zip ( & mut it) {
509509 assert_eq ! ( * x, vi[ [ i, j] ] ) ;
510510 }
511511 assert ! ( it. next( ) . is_none( ) ) ;
@@ -2071,9 +2071,8 @@ fn test_view_from_shape_ptr() {
20712071#[ test]
20722072fn test_view_from_shape_ptr_deny_neg_strides ( ) {
20732073 let data = [ 0 , 1 , 2 , 3 , 4 , 5 ] ;
2074- let _view = unsafe {
2075- ArrayView :: from_shape_ptr ( ( 2 , 3 ) . strides ( ( -3isize as usize , 1 ) ) , data. as_ptr ( ) )
2076- } ;
2074+ let _view =
2075+ unsafe { ArrayView :: from_shape_ptr ( ( 2 , 3 ) . strides ( ( -3isize as usize , 1 ) ) , data. as_ptr ( ) ) } ;
20772076}
20782077
20792078#[ should_panic( expected = "Unsupported" ) ]
@@ -2466,74 +2465,48 @@ mod array_cow_tests {
24662465
24672466#[ test]
24682467fn test_remove_index ( ) {
2469- let mut a = arr2 ( & [ [ 1 , 2 , 3 ] ,
2470- [ 4 , 5 , 6 ] ,
2471- [ 7 , 8 , 9 ] ,
2472- [ 10 , 11 , 12 ] ] ) ;
2468+ let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
24732469 a. remove_index ( Axis ( 0 ) , 1 ) ;
24742470 a. remove_index ( Axis ( 1 ) , 2 ) ;
24752471 assert_eq ! ( a. shape( ) , & [ 3 , 2 ] ) ;
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 ] ] ) ;
2472+ assert_eq ! ( a, array![ [ 1 , 2 ] , [ 7 , 8 ] , [ 10 , 11 ] ] ) ;
2473+
2474+ let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
24852475 a. invert_axis ( Axis ( 0 ) ) ;
24862476 a. remove_index ( Axis ( 0 ) , 1 ) ;
24872477 a. remove_index ( Axis ( 1 ) , 2 ) ;
24882478 assert_eq ! ( a. shape( ) , & [ 3 , 2 ] ) ;
2489- assert_eq ! ( a,
2490- array![ [ 10 , 11 ] ,
2491- [ 4 , 5 ] ,
2492- [ 1 , 2 ] ] ) ;
2479+ assert_eq ! ( a, array![ [ 10 , 11 ] , [ 4 , 5 ] , [ 1 , 2 ] ] ) ;
24932480
24942481 a. remove_index ( Axis ( 1 ) , 1 ) ;
24952482
24962483 assert_eq ! ( a. shape( ) , & [ 3 , 1 ] ) ;
2497- assert_eq ! ( a,
2498- array![ [ 10 ] ,
2499- [ 4 ] ,
2500- [ 1 ] ] ) ;
2484+ assert_eq ! ( a, array![ [ 10 ] , [ 4 ] , [ 1 ] ] ) ;
25012485 a. remove_index ( Axis ( 1 ) , 0 ) ;
25022486 assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2503- assert_eq ! ( a,
2504- array![ [ ] ,
2505- [ ] ,
2506- [ ] ] ) ;
2487+ assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
25072488}
25082489
2509- #[ should_panic( expected= "must be less" ) ]
2490+ #[ should_panic( expected = "must be less" ) ]
25102491#[ test]
25112492fn test_remove_index_oob1 ( ) {
2512- let mut a = arr2 ( & [ [ 1 , 2 , 3 ] ,
2513- [ 4 , 5 , 6 ] ,
2514- [ 7 , 8 , 9 ] ,
2515- [ 10 , 11 , 12 ] ] ) ;
2493+ let mut a = arr2 ( & [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ] ) ;
25162494 a. remove_index ( Axis ( 0 ) , 4 ) ;
25172495}
25182496
2519- #[ should_panic( expected= "must be less" ) ]
2497+ #[ should_panic( expected = "must be less" ) ]
25202498#[ test]
25212499fn test_remove_index_oob2 ( ) {
25222500 let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
25232501 a. remove_index ( Axis ( 1 ) , 0 ) ;
25242502 assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2525- assert_eq ! ( a,
2526- array![ [ ] ,
2527- [ ] ,
2528- [ ] ] ) ;
2503+ assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
25292504 a. remove_index ( Axis ( 0 ) , 1 ) ; // ok
2530- assert_eq ! ( a,
2531- array![ [ ] ,
2532- [ ] ] ) ;
2505+ assert_eq ! ( a, array![ [ ] , [ ] ] ) ;
25332506 a. remove_index ( Axis ( 1 ) , 0 ) ; // oob
25342507}
25352508
2536- #[ should_panic( expected= "index out of bounds" ) ]
2509+ #[ should_panic( expected = "index out of bounds" ) ]
25372510#[ test]
25382511fn test_remove_index_oob3 ( ) {
25392512 let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
@@ -2552,14 +2525,10 @@ fn test_split_complex_view() {
25522525
25532526#[ test]
25542527fn test_split_complex_view_roundtrip ( ) {
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] ] )
2528+ let a_re = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( i, j, _k) | i * j) ;
2529+ let a_im = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( _i, _j, k) | k) ;
2530+ let a = Array3 :: from_shape_fn ( ( 3 , 1 , 5 ) , |( i, j, k) | {
2531+ Complex :: new ( a_re[ [ i, j, k] ] , a_im[ [ i, j, k] ] )
25632532 } ) ;
25642533 let Complex { re, im } = a. view ( ) . split_complex ( ) ;
25652534 assert_eq ! ( a_re, re) ;
@@ -2590,18 +2559,18 @@ fn test_split_complex_zerod() {
25902559
25912560#[ test]
25922561fn test_split_complex_permuted ( ) {
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 ] ) ;
2562+ let a = Array3 :: from_shape_fn ( ( 3 , 4 , 5 ) , |( i, j, k) | Complex :: new ( i * k + j, k) ) ;
2563+ let permuted = a. view ( ) . permuted_axes ( [ 1 , 0 , 2 ] ) ;
25972564 let Complex { re, im } = permuted. split_complex ( ) ;
2598- assert_eq ! ( re. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 11 ) ;
2599- assert_eq ! ( im. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 4 ) ;
2565+ assert_eq ! ( re. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 11 ) ;
2566+ assert_eq ! ( im. get( ( 3 , 2 , 4 ) ) . unwrap( ) , & 4 ) ;
26002567}
26012568
26022569#[ test]
26032570fn test_split_complex_invert_axis ( ) {
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 ) ) ;
2571+ let mut a = Array :: from_shape_fn ( ( 2 , 3 , 2 ) , |( i, j, k) | {
2572+ Complex :: new ( i as f64 + j as f64 , i as f64 + k as f64 )
2573+ } ) ;
26052574 a. invert_axis ( Axis ( 1 ) ) ;
26062575 let cmplx = a. view ( ) . split_complex ( ) ;
26072576 assert_eq ! ( cmplx. re, a. mapv( |z| z. re) ) ;
0 commit comments