Repository navigation
Additional arithmetic operations/variants #697
Description
Activity
To my surprise I also have to write
momentum.bf += &(&gradient.bf * &gradient.bf);
instead ofmomentum.bf += &gradient.bf * &gradient.bf;
more or less the same error as above (trying to do a scalar operation). All variables areArray1<f32>
Do I lack some understanding of references Rust?hi, we can look at this if you provide example code for the problem or tell us the types of all the incoming variables
let a: Array2<f32> = arr2(&[[2.0, 3.0], [4.0, 5.0]]); let c: Array2<f32> = arr2(&[[1.0, 0.0], [0.0, 1.0]]); let mut d: Array2<f32> = Array2::zeros((2,2)); d = 2.0 * (&a / c.map(|x| x+1.0)); // &B @ B missing? d += b.t().dot(&a); // C @= B missing? d += &a * &a; // also C @= B { let e = &mut d; *e = a.dot(&c); // works *e = &a.dot(&c); // why do i need to remove the borrow *e = e + a.dot(&a); // &mut B @ B missing? *e = a.dot(&a) + e; // B @ &mut B missing? *e = e + e; // &mut B @ &mut B missing? }I am not sure if this me not understanding Rust or if there are some variants missing in
impl_ops.rs.
In the comment I wrote which implementations might be missing in term os doc.
If you think that I am right I would give the implementation a shot.Thanks! You're probably right - the ones you ask about as missing are not listed in the docs as being present:
https://docs.rs/ndarray/0.12.1/ndarray/struct.ArrayBase.html#arithmetic-operations
I'm not sure all of these should exist. I know it seems silly to say it like that — but adding one rule might result in dozens of additional impl blocks per rule.
Playground link for your example https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b5f6f01f0151d31d305a89e657810925
Are you concerned about the amount of code that will get generated?
Yes. Maybe there is a way to simplify it somehow.
- changed the title
[-]Inplace operation with map error[/-][+]Additional arithmetic operations/variants[/+]on Sep 4, 2019 I do understand the bloat concern @bluss, but the error message you get from the compiler on this issue is particularly confusing compared to the simplicity of the operation you are trying to perform.
I bumped into it myself while I was working on another example for
ndarray-examplesand it took me a while to figure it out.I'd be happy to work on this to expand the list of admitted operands combinations if you are willing to merge it/consider to merge it.
Let's make an issue to discuss this. There are loads of things that can be improved with the arithmetic ops.
@LukeMathWalker Let me know what you think. I've tried to make it specific #699
@LukeMathWalker I can't promise I have the bandwidth to approve it. We need to merge changes that I haven't approved too, otherwise we'll be stuck here :)
I guess what I meant was "unless you strongly feel against it" 👍 I'll contribute to the discussion in #699
Reacted by bluss
Hello
i get an type mismatch error when in do
Edit: o_gate has the type
Array1<f32>Error
i think it tries to do a scalar operation
When i don't try to do it inplace it works
We use inplace operations when concerned about the memory usage right?