Skip to content

Commit 15b0808

Browse files
committed
Add test for issue #1018
1 parent cadee2b commit 15b0808

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/array.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,29 @@ fn map_memory_order() {
17881788
assert_eq!(amap.strides(), v.strides());
17891789
}
17901790

1791+
#[test]
1792+
fn map_mut_with_unsharing() {
1793+
// Fortran-layout `ArcArray`.
1794+
let a = rcarr2(&[[0, 5], [1, 6], [2, 7], [3, 8], [4, 9]]).reversed_axes();
1795+
assert_eq!(a.shape(), &[2, 5]);
1796+
assert_eq!(a.strides(), &[1, 2]);
1797+
assert_eq!(
1798+
a.as_slice_memory_order(),
1799+
Some(&[0, 5, 1, 6, 2, 7, 3, 8, 4, 9][..])
1800+
);
1801+
1802+
// Shared reference of a portion of `a`.
1803+
let mut b = a.clone().slice_move(s![.., ..2]);
1804+
assert_eq!(b.shape(), &[2, 2]);
1805+
assert_eq!(b.strides(), &[1, 2]);
1806+
assert_eq!(b.as_slice_memory_order(), Some(&[0, 5, 1, 6][..]));
1807+
assert_eq!(b, array![[0, 1], [5, 6]]);
1808+
1809+
// `.map_mut()` unshares the data. Earlier versions of `ndarray` failed
1810+
// this assertion. See #1018.
1811+
assert_eq!(b.map_mut(|&mut x| x + 10), array![[10, 11], [15, 16]]);
1812+
}
1813+
17911814
#[test]
17921815
fn test_view_from_shape() {
17931816
let s = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

0 commit comments

Comments
 (0)