Skip to content

Commit 02df153

Browse files
committed
Add more tests for NdIndex
1 parent c9b53c1 commit 02df153

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/dimension.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use ndarray::{
88
Axis,
99
Dimension,
1010
Dim,
11+
IntoDimension,
1112
};
1213

1314
#[test]
@@ -172,3 +173,37 @@ fn test_array_view() {
172173
test_dim(&Dim(vec![1, 1, 2, 3]));
173174
test_dim(&Dim(7));
174175
}
176+
177+
#[test]
178+
fn test_all_ndindex() {
179+
macro_rules! ndindex {
180+
($($i:expr),*) => {
181+
for &rev in &[false, true] {
182+
// rev is for C / F order
183+
let size = $($i *)* 1;
184+
let mut a = Array::linspace(0., (size - 1) as f64, size);
185+
if rev {
186+
a = a.reversed_axes();
187+
}
188+
for (i, &elt) in a.indexed_iter() {
189+
let dim = i.into_dimension();
190+
assert_eq!(elt, a[i]);
191+
assert_eq!(elt, a[dim]);
192+
}
193+
let dim = a.shape().to_vec();
194+
let b = a.broadcast(dim).unwrap();
195+
for (i, &elt) in a.indexed_iter() {
196+
let dim = i.into_dimension();
197+
assert_eq!(elt, b[dim]);
198+
assert_eq!(elt, b[dim.slice()]);
199+
}
200+
}
201+
}
202+
}
203+
ndindex!(10);
204+
ndindex!(10, 4);
205+
ndindex!(10, 4, 3);
206+
ndindex!(10, 4, 3, 2);
207+
ndindex!(10, 4, 3, 2, 2);
208+
ndindex!(10, 4, 3, 2, 2, 2);
209+
}

0 commit comments

Comments
 (0)