ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

impl Mul<Array<Complex<T>>> for T

Open cavemanloverboy opened this issue 2 years ago • 5 comments
trafficstars

I did a quick scan of the issues and didn't see this. For an array: Array<Complex<f64>> (for example), i think it's perfectly reasonable to expect

let output: Array<Complex<f64>> = 2.0_f64 * array;

to work. I've only ever gotten a rhs mul e.g. array * 2.0 to work. (see example, non-working example). Is there a reason this hasn't been done, e.g. orphan rules?

cavemanloverboy avatar Jan 19 '23 21:01 cavemanloverboy

I think it should be possible, actually, here's an example

cavemanloverboy avatar Jan 19 '23 21:01 cavemanloverboy

The implementation can also be done for Complex<f32> and Complex<f64> for Array<Complex<f32>> and Array<Complex<f64>>

cavemanloverboy avatar Jan 19 '23 21:01 cavemanloverboy

Also, doing this for Div will allow for things like 1.0 / array for a complex array.

cavemanloverboy avatar Jan 20 '23 18:01 cavemanloverboy

Please see this for doc on scalars on the left hand side: https://docs.rs/ndarray/latest/ndarray/trait.ScalarOperand.html

Just for baseline/background. I don't know if this is a good idea, don't know if there are any drawbacks. Since complex implements mixed float-complex operations, we have the necessary precedent to consider it.

bluss avatar Jan 21 '23 15:01 bluss