ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

Give MathCell arithmetic ops implementations when MathCell is left value

Open SparrowLii opened this issue 4 years ago • 1 comments
trafficstars

Update #969 Four functions are implemented for ArrayView<MathCell, _> in impl_methods.rs: zip_cell_with, zip_cell_with_elem, zip_cell_with_same_shape, zip_cell_with_by_rows. Operator overloading is implemented in impl_ops.rs for the following situations: ArrayView<MathCell, _> binary_op &ArrayBase ArrayView<MathCell, _> binary_op Scalar ArrayView<MathCell, _> assign_op &ArrayBase ArrayView<MathCell, _> assign_op Scalar

The unresolved problems are:

  1. Currently MathCell can only be left value. The main reason are: (1) Conflicts occur when compiling MathCell<A> op MathCell<B> (2) Rust's orphan rules. We can't write code like this:impl<T> Add<MathCell<T>> for T. This will cause E0210 error

  2. The value in MathCell must be Copy This is because the value in MathCell needs to be retrieved using the get() method. We cannot get &T from &MathCell<T> unless we create a new structure MathRefCell(RefCell<T>)

SparrowLii avatar May 21 '21 12:05 SparrowLii

We don't implement ArrayViewMut + x (only ArrayViewMut += x), and this should be the same way IMO. I.e we want the += and similar ops. I hope we can do with without adding new copies like all the new .zip* methods.

bluss avatar May 21 '21 15:05 bluss