File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -638,6 +638,25 @@ pub type Ixs = isize;
638
638
/// - `B @ &A` which consumes `B`, updates it with the result, and returns it
639
639
/// - `C @= &A` which performs an arithmetic operation in place
640
640
///
641
+ /// Note that the element type needs to implement the operator trait and the
642
+ /// `Clone` trait.
643
+ ///
644
+ /// ```
645
+ /// use ndarray::{array, ArrayView1};
646
+ ///
647
+ /// let owned1 = array![1, 2];
648
+ /// let owned2 = array![3, 4];
649
+ /// let view1 = ArrayView1::from(&[5, 6]);
650
+ /// let view2 = ArrayView1::from(&[7, 8]);
651
+ /// let mut mutable = array![9, 10];
652
+ ///
653
+ /// let sum1 = &view1 + &view2; // Allocates a new array. Note the explicit `&`.
654
+ /// // let sum2 = view1 + &view2; // This doesn't work because `view1` is not an owned array.
655
+ /// let sum3 = owned1 + view1; // Consumes `owned1`, updates it, and returns it.
656
+ /// let sum4 = owned2 + &view2; // Consumes `owned2`, updates it, and returns it.
657
+ /// mutable += &view2; // Updates `mutable` in-place.
658
+ /// ```
659
+ ///
641
660
/// ### Binary Operators with Array and Scalar
642
661
///
643
662
/// The trait [`ScalarOperand`](trait.ScalarOperand.html) marks types that can be used in arithmetic
You can’t perform that action at this time.
0 commit comments