9
9
10
10
use approx:: assert_relative_eq;
11
11
use defmac:: defmac;
12
- use itertools:: { zip, Itertools } ;
12
+ use itertools:: Itertools ;
13
+ use ndarray:: indices;
13
14
use ndarray:: prelude:: * ;
14
15
use ndarray:: { arr3, rcarr2} ;
15
- use ndarray:: indices;
16
16
use ndarray:: { Slice , SliceInfo , SliceInfoElem } ;
17
17
use num_complex:: Complex ;
18
18
use std:: convert:: TryFrom ;
@@ -499,13 +499,13 @@ fn test_index() {
499
499
* elt = i;
500
500
}
501
501
502
- for ( ( i, j) , a) in zip ( indices ( ( 2 , 3 ) ) , & A ) {
502
+ for ( ( i, j) , a) in indices ( ( 2 , 3 ) ) . into_iter ( ) . zip ( & A ) {
503
503
assert_eq ! ( * a, A [ [ i, j] ] ) ;
504
504
}
505
505
506
506
let vi = A . slice ( s ! [ 1 .., ..; 2 ] ) ;
507
507
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) {
509
509
assert_eq ! ( * x, vi[ [ i, j] ] ) ;
510
510
}
511
511
assert ! ( it. next( ) . is_none( ) ) ;
@@ -2071,9 +2071,8 @@ fn test_view_from_shape_ptr() {
2071
2071
#[ test]
2072
2072
fn test_view_from_shape_ptr_deny_neg_strides ( ) {
2073
2073
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 ( ) ) } ;
2077
2076
}
2078
2077
2079
2078
#[ should_panic( expected = "Unsupported" ) ]
@@ -2466,74 +2465,48 @@ mod array_cow_tests {
2466
2465
2467
2466
#[ test]
2468
2467
fn 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 ] ] ) ;
2473
2469
a. remove_index ( Axis ( 0 ) , 1 ) ;
2474
2470
a. remove_index ( Axis ( 1 ) , 2 ) ;
2475
2471
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 ] ] ) ;
2485
2475
a. invert_axis ( Axis ( 0 ) ) ;
2486
2476
a. remove_index ( Axis ( 0 ) , 1 ) ;
2487
2477
a. remove_index ( Axis ( 1 ) , 2 ) ;
2488
2478
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 ] ] ) ;
2493
2480
2494
2481
a. remove_index ( Axis ( 1 ) , 1 ) ;
2495
2482
2496
2483
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 ] ] ) ;
2501
2485
a. remove_index ( Axis ( 1 ) , 0 ) ;
2502
2486
assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2503
- assert_eq ! ( a,
2504
- array![ [ ] ,
2505
- [ ] ,
2506
- [ ] ] ) ;
2487
+ assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
2507
2488
}
2508
2489
2509
- #[ should_panic( expected= "must be less" ) ]
2490
+ #[ should_panic( expected = "must be less" ) ]
2510
2491
#[ test]
2511
2492
fn 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 ] ] ) ;
2516
2494
a. remove_index ( Axis ( 0 ) , 4 ) ;
2517
2495
}
2518
2496
2519
- #[ should_panic( expected= "must be less" ) ]
2497
+ #[ should_panic( expected = "must be less" ) ]
2520
2498
#[ test]
2521
2499
fn test_remove_index_oob2 ( ) {
2522
2500
let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
2523
2501
a. remove_index ( Axis ( 1 ) , 0 ) ;
2524
2502
assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2525
- assert_eq ! ( a,
2526
- array![ [ ] ,
2527
- [ ] ,
2528
- [ ] ] ) ;
2503
+ assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
2529
2504
a. remove_index ( Axis ( 0 ) , 1 ) ; // ok
2530
- assert_eq ! ( a,
2531
- array![ [ ] ,
2532
- [ ] ] ) ;
2505
+ assert_eq ! ( a, array![ [ ] , [ ] ] ) ;
2533
2506
a. remove_index ( Axis ( 1 ) , 0 ) ; // oob
2534
2507
}
2535
2508
2536
- #[ should_panic( expected= "index out of bounds" ) ]
2509
+ #[ should_panic( expected = "index out of bounds" ) ]
2537
2510
#[ test]
2538
2511
fn test_remove_index_oob3 ( ) {
2539
2512
let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
@@ -2552,14 +2525,10 @@ fn test_split_complex_view() {
2552
2525
2553
2526
#[ test]
2554
2527
fn 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] ] )
2563
2532
} ) ;
2564
2533
let Complex { re, im } = a. view ( ) . split_complex ( ) ;
2565
2534
assert_eq ! ( a_re, re) ;
@@ -2590,18 +2559,18 @@ fn test_split_complex_zerod() {
2590
2559
2591
2560
#[ test]
2592
2561
fn 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 ] ) ;
2597
2564
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 ) ;
2600
2567
}
2601
2568
2602
2569
#[ test]
2603
2570
fn 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
+ } ) ;
2605
2574
a. invert_axis ( Axis ( 1 ) ) ;
2606
2575
let cmplx = a. view ( ) . split_complex ( ) ;
2607
2576
assert_eq ! ( cmplx. re, a. mapv( |z| z. re) ) ;
0 commit comments