|
7 | 7 |
|
8 | 8 | use defmac::defmac;
|
9 | 9 | use ndarray::prelude::*;
|
| 10 | +use ndarray::arr3; |
10 | 11 | use ndarray::Zip;
|
11 | 12 |
|
12 | 13 | #[test]
|
@@ -164,6 +165,43 @@ fn test_ones() {
|
164 | 165 | assert_eq!(a, b);
|
165 | 166 | }
|
166 | 167 |
|
| 168 | +#[test] |
| 169 | +fn test_from_shape_empty_with_neg_stride() { |
| 170 | + // Issue #998, negative strides for an axis where it doesn't matter. |
| 171 | + let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; |
| 172 | + let v = s[..12].to_vec(); |
| 173 | + let v_ptr = v.as_ptr(); |
| 174 | + let a = Array::from_shape_vec((2, 0, 2).strides((1, -4isize as usize, 2)), v).unwrap(); |
| 175 | + assert_eq!(a, arr3(&[[[0; 2]; 0]; 2])); |
| 176 | + assert_eq!(a.as_ptr(), v_ptr); |
| 177 | +} |
| 178 | + |
| 179 | +#[test] |
| 180 | +fn test_from_shape_with_neg_stride() { |
| 181 | + // Issue #998, negative strides for an axis where it doesn't matter. |
| 182 | + let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; |
| 183 | + let v = s[..12].to_vec(); |
| 184 | + let v_ptr = v.as_ptr(); |
| 185 | + let a = Array::from_shape_vec((2, 1, 2).strides((1, -4isize as usize, 2)), v).unwrap(); |
| 186 | + assert_eq!(a, arr3(&[[[0, 2]], |
| 187 | + [[1, 3]]])); |
| 188 | + assert_eq!(a.as_ptr(), v_ptr); |
| 189 | +} |
| 190 | + |
| 191 | +#[test] |
| 192 | +fn test_from_shape_2_2_2_with_neg_stride() { |
| 193 | + // Issue #998, negative strides for an axis where it doesn't matter. |
| 194 | + let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; |
| 195 | + let v = s[..12].to_vec(); |
| 196 | + let v_ptr = v.as_ptr(); |
| 197 | + let a = Array::from_shape_vec((2, 2, 2).strides((1, -4isize as usize, 2)), v).unwrap(); |
| 198 | + assert_eq!(a, arr3(&[[[4, 6], |
| 199 | + [0, 2]], |
| 200 | + [[5, 7], |
| 201 | + [1, 3]]])); |
| 202 | + assert_eq!(a.as_ptr(), v_ptr.wrapping_add(4)); |
| 203 | +} |
| 204 | + |
167 | 205 | #[should_panic]
|
168 | 206 | #[test]
|
169 | 207 | fn deny_wraparound_zeros() {
|
|
0 commit comments