Skip to content

Commit 45e6b5d

Browse files
committed
Fix trait bound on arr1 (op) &arr2
The implementation of `arr1 (op) &arr2` mutates `arr1` for efficiency, but this caused surprising behavior if `arr1` was `ArrayViewMut`. This commit requires that `arr` own its data to avoid surprising side effects. This is an example of the old behavior that was surprising: ```rust extern crate ndarray; fn main() { let mut a = array![1., 2.]; let b = array![3., 4.]; // Prints a = [1, 2]. println!("a = {}", a); { let a_view_mut = a.view_mut(); // Prints a + b = [4, 6]. println!("a + b = {}", a_view_mut + &b); } // Prints a = [4, 6]; would expect a = [1, 2]. println!("a = {}", a); } ``` Note that while this is a breaking change, the stricter trait bound is actually the correct bound according to the documentation.
1 parent 0a899c7 commit 45e6b5d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/impl_ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<A, S, S2, D, E> $trt<ArrayBase<S2, E>> for ArrayBase<S, D>
8282
/// **Panics** if broadcasting isn’t possible.
8383
impl<'a, A, S, S2, D, E> $trt<&'a ArrayBase<S2, E>> for ArrayBase<S, D>
8484
where A: Clone + $trt<A, Output=A>,
85-
S: DataMut<Elem=A>,
85+
S: DataOwned<Elem=A> + DataMut,
8686
S2: Data<Elem=A>,
8787
D: Dimension,
8888
E: Dimension,

0 commit comments

Comments
 (0)