@@ -11,7 +11,9 @@ use approx::assert_relative_eq;
11
11
use defmac:: defmac;
12
12
use itertools:: { zip, Itertools } ;
13
13
use 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 } ;
15
17
use num_complex:: Complex ;
16
18
use std:: convert:: TryFrom ;
17
19
@@ -2069,8 +2071,9 @@ fn test_view_from_shape_ptr() {
2069
2071
#[ test]
2070
2072
fn test_view_from_shape_ptr_deny_neg_strides ( ) {
2071
2073
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
+ } ;
2074
2077
}
2075
2078
2076
2079
#[ should_panic( expected = "Unsupported" ) ]
@@ -2463,48 +2466,74 @@ mod array_cow_tests {
2463
2466
2464
2467
#[ test]
2465
2468
fn 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 ] ] ) ;
2467
2473
a. remove_index ( Axis ( 0 ) , 1 ) ;
2468
2474
a. remove_index ( Axis ( 1 ) , 2 ) ;
2469
2475
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 ] ] ) ;
2473
2485
a. invert_axis ( Axis ( 0 ) ) ;
2474
2486
a. remove_index ( Axis ( 0 ) , 1 ) ;
2475
2487
a. remove_index ( Axis ( 1 ) , 2 ) ;
2476
2488
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 ] ] ) ;
2478
2493
2479
2494
a. remove_index ( Axis ( 1 ) , 1 ) ;
2480
2495
2481
2496
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 ] ] ) ;
2483
2501
a. remove_index ( Axis ( 1 ) , 0 ) ;
2484
2502
assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2485
- assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
2503
+ assert_eq ! ( a,
2504
+ array![ [ ] ,
2505
+ [ ] ,
2506
+ [ ] ] ) ;
2486
2507
}
2487
2508
2488
- #[ should_panic( expected = "must be less" ) ]
2509
+ #[ should_panic( expected= "must be less" ) ]
2489
2510
#[ test]
2490
2511
fn 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 ] ] ) ;
2492
2516
a. remove_index ( Axis ( 0 ) , 4 ) ;
2493
2517
}
2494
2518
2495
- #[ should_panic( expected = "must be less" ) ]
2519
+ #[ should_panic( expected= "must be less" ) ]
2496
2520
#[ test]
2497
2521
fn test_remove_index_oob2 ( ) {
2498
2522
let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
2499
2523
a. remove_index ( Axis ( 1 ) , 0 ) ;
2500
2524
assert_eq ! ( a. shape( ) , & [ 3 , 0 ] ) ;
2501
- assert_eq ! ( a, array![ [ ] , [ ] , [ ] ] ) ;
2525
+ assert_eq ! ( a,
2526
+ array![ [ ] ,
2527
+ [ ] ,
2528
+ [ ] ] ) ;
2502
2529
a. remove_index ( Axis ( 0 ) , 1 ) ; // ok
2503
- assert_eq ! ( a, array![ [ ] , [ ] ] ) ;
2530
+ assert_eq ! ( a,
2531
+ array![ [ ] ,
2532
+ [ ] ] ) ;
2504
2533
a. remove_index ( Axis ( 1 ) , 0 ) ; // oob
2505
2534
}
2506
2535
2507
- #[ should_panic( expected = "index out of bounds" ) ]
2536
+ #[ should_panic( expected= "index out of bounds" ) ]
2508
2537
#[ test]
2509
2538
fn test_remove_index_oob3 ( ) {
2510
2539
let mut a = array ! [ [ 10 ] , [ 4 ] , [ 1 ] ] ;
@@ -2523,10 +2552,14 @@ fn test_split_complex_view() {
2523
2552
2524
2553
#[ test]
2525
2554
fn 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] ] )
2530
2563
} ) ;
2531
2564
let Complex { re, im } = a. view ( ) . split_complex ( ) ;
2532
2565
assert_eq ! ( a_re, re) ;
@@ -2557,18 +2590,18 @@ fn test_split_complex_zerod() {
2557
2590
2558
2591
#[ test]
2559
2592
fn 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 ] ) ;
2562
2597
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 ) ;
2565
2600
}
2566
2601
2567
2602
#[ test]
2568
2603
fn 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 ) ) ;
2572
2605
a. invert_axis ( Axis ( 1 ) ) ;
2573
2606
let cmplx = a. view ( ) . split_complex ( ) ;
2574
2607
assert_eq ! ( cmplx. re, a. mapv( |z| z. re) ) ;
0 commit comments