-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathshrink_to_fit.rs
More file actions
55 lines (51 loc) · 1.5 KB
/
shrink_to_fit.rs
File metadata and controls
55 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use ndarray::{s, Array};
#[test]
fn dim_0() {
let mut raw_vec = Vec::new();
for i in 0..4 * 5 * 6 {
raw_vec.push(i);
}
let a = Array::from_shape_vec((4, 5, 6), raw_vec).unwrap();
let mut a_slice = a.slice_move(s![0..2, .., ..]);
let a_slice_clone = a_slice.view().to_owned();
a_slice.shrink_to_fit();
assert_eq!(a_slice, a_slice_clone);
}
#[test]
fn swap_axis_dim_0() {
let mut raw_vec = Vec::new();
for i in 0..4 * 5 * 6 {
raw_vec.push(i);
}
let mut a = Array::from_shape_vec((4, 5, 6), raw_vec).unwrap();
a.swap_axes(0, 1);
let mut a_slice = a.slice_move(s![2..3, .., ..]);
let a_slice_clone = a_slice.view().to_owned();
a_slice.shrink_to_fit();
assert_eq!(a_slice, a_slice_clone);
}
#[test]
fn swap_axis_dim() {
let mut raw_vec = Vec::new();
for i in 0..4 * 5 * 6 {
raw_vec.push(i);
}
let mut a = Array::from_shape_vec((4, 5, 6), raw_vec).unwrap();
a.swap_axes(2, 1);
let mut a_slice = a.slice_move(s![2..3, 0..3, 0..;2]);
let a_slice_clone = a_slice.view().to_owned();
a_slice.shrink_to_fit();
assert_eq!(a_slice, a_slice_clone);
}
#[test]
fn stride_negative() {
let mut raw_vec = Vec::new();
for i in 0..4 * 5 * 6 {
raw_vec.push(i);
}
let a = Array::from_shape_vec((4, 5, 6), raw_vec).unwrap();
let mut a_slice = a.slice_move(s![2..3, 0..3, 0..;-1]);
let a_slice_clone = a_slice.view().to_owned();
a_slice.shrink_to_fit();
assert_eq!(a_slice, a_slice_clone);
}