-
Notifications
You must be signed in to change notification settings - Fork 321
/
Copy pathzip.rs
72 lines (56 loc) · 1.29 KB
/
zip.rs
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
extern crate ndarray;
extern crate ndarray_parallel;
use ndarray::prelude::*;
use ndarray::Zip;
const M: usize = 1024 * 10;
const N: usize = 100;
#[test]
fn test_zip_1() {
let mut a = Array2::<f64>::zeros((M, N));
Zip::from(&mut a).par_apply(|x| *x = x.exp());
}
#[test]
fn test_zip_index_1() {
let mut a = Array2::default((10, 10));
Zip::indexed(&mut a).par_apply(|i, x| {
*x = i;
});
for (i, elt) in a.indexed_iter() {
assert_eq!(*elt, i);
}
}
#[test]
fn test_zip_index_2() {
let mut a = Array2::default((M, N));
Zip::indexed(&mut a).par_apply(|i, x| {
*x = i;
});
for (i, elt) in a.indexed_iter() {
assert_eq!(*elt, i);
}
}
#[test]
fn test_zip_index_3() {
let mut a = Array::default((1, 2, 1, 2, 3));
Zip::indexed(&mut a).par_apply(|i, x| {
*x = i;
});
for (i, elt) in a.indexed_iter() {
assert_eq!(*elt, i);
}
}
#[test]
fn test_zip_index_4() {
let mut a = Array2::zeros((M, N));
let mut b = Array2::zeros((M, N));
Zip::indexed(&mut a).and(&mut b).par_apply(|(i, j), x, y| {
*x = i;
*y = j;
});
for ((i, _), elt) in a.indexed_iter() {
assert_eq!(*elt, i);
}
for ((_, j), elt) in b.indexed_iter() {
assert_eq!(*elt, j);
}
}