|
6 | 6 | )]
|
7 | 7 |
|
8 | 8 | use ndarray::prelude::*;
|
9 |
| -use ndarray::Zip; |
| 9 | +use ndarray::{arr3, Zip}; |
10 | 10 |
|
11 | 11 | // Edge Cases for Windows iterator:
|
12 | 12 | //
|
@@ -79,7 +79,6 @@ fn windows_iterator_2d() {
|
79 | 79 | /// Simple test for iterating 3d-arrays via `Windows`.
|
80 | 80 | #[test]
|
81 | 81 | fn windows_iterator_3d() {
|
82 |
| - use ndarray::arr3; |
83 | 82 | let a = Array::from_iter(10..37).into_shape((3, 3, 3)).unwrap();
|
84 | 83 | itertools::assert_equal(
|
85 | 84 | a.windows(Dim((2, 2, 2))),
|
@@ -117,6 +116,87 @@ fn test_window_zip() {
|
117 | 116 | }
|
118 | 117 | }
|
119 | 118 |
|
| 119 | +/// Test verifies that non existant Axis results in panic |
| 120 | +#[test] |
| 121 | +#[should_panic] |
| 122 | +fn axis_windows_outofbound() { |
| 123 | + let a = Array::from_iter(10..37).into_shape((3, 3, 3)).unwrap(); |
| 124 | + a.axis_windows(Axis(4), 2); |
| 125 | +} |
| 126 | + |
| 127 | +/// Test verifies that zero sizes results in panic |
| 128 | +#[test] |
| 129 | +#[should_panic] |
| 130 | +fn axis_windows_zero_size() { |
| 131 | + let a = Array::from_iter(10..37).into_shape((3, 3, 3)).unwrap(); |
| 132 | + a.axis_windows(Axis(0), 0); |
| 133 | +} |
| 134 | + |
| 135 | +/// Test verifies that over sized windows yield nothing |
| 136 | +#[test] |
| 137 | +fn axis_windows_oversized() { |
| 138 | + let a = Array::from_iter(10..37).into_shape((3, 3, 3)).unwrap(); |
| 139 | + let mut iter = a.axis_windows(Axis(2), 4).into_iter(); |
| 140 | + assert_eq!(iter.next(), None); |
| 141 | +} |
| 142 | + |
| 143 | +/// Simple test for iterating 1d-arrays via `Axis Windows`. |
| 144 | +#[test] |
| 145 | +fn test_axis_windows_1d() { |
| 146 | + let a = Array::from_iter(10..20).into_shape(10).unwrap(); |
| 147 | + |
| 148 | + itertools::assert_equal( |
| 149 | + a.axis_windows(Axis(0), 5), |
| 150 | + vec![ |
| 151 | + arr1(&[10, 11, 12, 13, 14]), |
| 152 | + arr1(&[11, 12, 13, 14, 15]), |
| 153 | + arr1(&[12, 13, 14, 15, 16]), |
| 154 | + arr1(&[13, 14, 15, 16, 17]), |
| 155 | + arr1(&[14, 15, 16, 17, 18]), |
| 156 | + arr1(&[15, 16, 17, 18, 19]), |
| 157 | + ], |
| 158 | + ); |
| 159 | +} |
| 160 | + |
| 161 | +/// Simple test for iterating 2d-arrays via `Axis Windows`. |
| 162 | +#[test] |
| 163 | +fn test_axis_windows_2d() { |
| 164 | + let a = Array::from_iter(10..30).into_shape((5, 4)).unwrap(); |
| 165 | + |
| 166 | + itertools::assert_equal( |
| 167 | + a.axis_windows(Axis(0), 2), |
| 168 | + vec![ |
| 169 | + arr2(&[[10, 11, 12, 13], [14, 15, 16, 17]]), |
| 170 | + arr2(&[[14, 15, 16, 17], [18, 19, 20, 21]]), |
| 171 | + arr2(&[[18, 19, 20, 21], [22, 23, 24, 25]]), |
| 172 | + arr2(&[[22, 23, 24, 25], [26, 27, 28, 29]]), |
| 173 | + ], |
| 174 | + ); |
| 175 | +} |
| 176 | + |
| 177 | +/// Simple test for iterating 3d-arrays via `Axis Windows`. |
| 178 | +#[test] |
| 179 | +fn test_axis_windows_3d() { |
| 180 | + let a = Array::from_iter(0..27).into_shape((3, 3, 3)).unwrap(); |
| 181 | + |
| 182 | + itertools::assert_equal( |
| 183 | + a.axis_windows(Axis(1), 2), |
| 184 | + vec![ |
| 185 | + arr3(&[ |
| 186 | + [[0, 1, 2], [3, 4, 5]], |
| 187 | + [[9, 10, 11], [12, 13, 14]], |
| 188 | + [[18, 19, 20], [21, 22, 23]], |
| 189 | + ]), |
| 190 | + arr3(&[ |
| 191 | + [[3, 4, 5], [6, 7, 8]], |
| 192 | + [[12, 13, 14], [15, 16, 17]], |
| 193 | + [[21, 22, 23], [24, 25, 26]], |
| 194 | + ]), |
| 195 | + ], |
| 196 | + ); |
| 197 | +} |
| 198 | + |
| 199 | + |
120 | 200 | #[test]
|
121 | 201 | fn test_window_neg_stride() {
|
122 | 202 | let array = Array::from_iter(1..10).into_shape((3, 3)).unwrap();
|
|
0 commit comments