Skip to content

Commit 3ee4ad3

Browse files
committed
parallel: Add tests for parallelized with indices
1 parent b1fccf3 commit 3ee4ad3

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

parallel/tests/zip.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
extern crate ndarray;
3+
extern crate ndarray_parallel;
4+
5+
use ndarray::prelude::*;
6+
use ndarray_parallel::prelude::*;
7+
8+
use ndarray::Zip;
9+
10+
const M: usize = 1024 * 10;
11+
const N: usize = 100;
12+
13+
#[test]
14+
fn test_zip_1() {
15+
let mut a = Array2::<f64>::zeros((M, N));
16+
17+
Zip::from(&mut a)
18+
.par_apply(|x| {
19+
*x = x.exp()
20+
});
21+
}
22+
23+
#[test]
24+
fn test_zip_index_1() {
25+
let mut a = Array2::default((10, 10));
26+
27+
Zip::indexed(&mut a)
28+
.par_apply(|i, x| {
29+
*x = i;
30+
});
31+
32+
for (i, elt) in a.indexed_iter() {
33+
assert_eq!(*elt, i);
34+
}
35+
}
36+
37+
#[test]
38+
fn test_zip_index_2() {
39+
let mut a = Array2::default((M, N));
40+
41+
Zip::indexed(&mut a)
42+
.par_apply(|i, x| {
43+
*x = i;
44+
});
45+
46+
for (i, elt) in a.indexed_iter() {
47+
assert_eq!(*elt, i);
48+
}
49+
}
50+
51+
#[test]
52+
fn test_zip_index_3() {
53+
let mut a = Array::default((1, 2, 1, 2, 3));
54+
55+
Zip::indexed(&mut a)
56+
.par_apply(|i, x| {
57+
*x = i;
58+
});
59+
60+
for (i, elt) in a.indexed_iter() {
61+
assert_eq!(*elt, i);
62+
}
63+
}
64+
65+
#[test]
66+
fn test_zip_index_4() {
67+
let mut a = Array2::zeros((M, N));
68+
let mut b = Array2::zeros((M, N));
69+
70+
Zip::indexed(&mut a)
71+
.and(&mut b)
72+
.par_apply(|(i, j), x, y| {
73+
*x = i;
74+
*y = j;
75+
});
76+
77+
for ((i, _), elt) in a.indexed_iter() {
78+
assert_eq!(*elt, i);
79+
}
80+
for ((_, j), elt) in b.indexed_iter() {
81+
assert_eq!(*elt, j);
82+
}
83+
}

0 commit comments

Comments
 (0)