-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathstore_and_extract.rs
More file actions
98 lines (91 loc) · 3.63 KB
/
store_and_extract.rs
File metadata and controls
98 lines (91 loc) · 3.63 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use ndarray::{arr0, arr1, arr2, s, ArcArray, ArrayBase, Dim, IxDyn, IxDynImpl, OwnedArcRepr, OwnedRepr};
// No test: ArcArray2, ArrayD
#[test]
fn store_many_dim_excrate() {
{
let a = arr0::<f32>(2.72);
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ArrayBase<OwnedRepr<f32>, Dim<[usize; 0]>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
{
let a = arr1::<f32>(&[2.72, 1., 2.]);
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ndarray::ArrayBase<OwnedRepr<f32>, Dim<[usize; 1]>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
{
let a = arr2(&[[3., 1., 2.2], [3.1, 4., 7.]]);
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ndarray::ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
{
// Test a sliced array.
let mut a = ArcArray::from_iter(0..32)
.into_shape_with_order((2, 2, 2, 4))
.unwrap();
a.slice_collapse(s![..;-1, .., .., ..2]);
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ndarray::ArrayBase<OwnedArcRepr<i32>, Dim<[usize; 4]>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
}
#[test]
fn serial_ixdyn_serde() {
{
let a = arr0::<f32>(2.72).into_dyn();
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ArrayBase<OwnedRepr<f32>, Dim<IxDynImpl>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
{
let a = arr1::<f32>(&[2.72, 1., 2.]).into_dyn();
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ArrayBase<OwnedRepr<f32>, Dim<IxDynImpl>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
{
let a = arr2(&[[3., 1., 2.2], [3.1, 4., 7.]])
.into_shape_with_order(IxDyn(&[3, 1, 1, 1, 2, 1]))
.unwrap();
let store_bytes = bincode::encode_to_vec(&a, bincode::config::standard()).unwrap();
println!("Bincode encode {:?} => {:?}", &a, store_bytes);
let res = bincode::decode_from_slice::<ArrayBase<OwnedRepr<f64>, Dim<IxDynImpl>>, _>(
&store_bytes,
bincode::config::standard(),
);
println!("{:?}", res);
assert_eq!(a, res.unwrap().0);
}
}