Skip to content

Commit e6f0b4f

Browse files
committed
Fix bug in raw_data_mut
1 parent b02588a commit e6f0b4f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ impl<A, D> Array<A, D> where D: Dimension
684684
pub fn raw_data_mut<'a>(&'a mut self) -> &'a mut [A]
685685
where A: Clone
686686
{
687+
self.ensure_unique();
687688
&mut Rc::make_mut(&mut self.data)[..]
688689
}
689690

tests/array.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,14 @@ fn map1()
336336
let c = a.map(|x| x);
337337
assert_eq!(a[(0, 0)], *c[(0, 0)]);
338338
}
339+
340+
#[test]
341+
fn raw_data_mut()
342+
{
343+
let mut a = arr2(&[[1., 2.], [3., 4.0f32]]);
344+
let mut b = a.clone();
345+
for elt in b.raw_data_mut() {
346+
*elt = 0.;
347+
}
348+
assert!(a != b, "{:?} != {:?}", a, b);
349+
}

0 commit comments

Comments
 (0)