You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0271]: type mismatch resolving `<f32 as std::ops::Mul<ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>>>::Output == f32`
--> src/main.rs:188:25
|
188 | a.h = &a.o_gate * c_post;
| ^ expected struct `ndarray::ArrayBase`, found f32
|
= note: expected type `ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
found type `f32`
= note: required because of the requirements on the impl of `std::ops::Mul<ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>>` for `&ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
error[E0277]: the trait bound `ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>: ndarray::impl_ops::ScalarOperand` is not satisfied
--> src/main.rs:188:25
|
188 | a.h = &a.o_gate * c_post;
| ^ the trait `ndarray::impl_ops::ScalarOperand` is not implemented for `ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
|
= note: required because of the requirements on the impl of `std::ops::Mul<ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>>` for `&ndarray::ArrayBase<ndarray::OwnedRepr<f32>, ndarray::dimension::dim::Dim<[usize; 1]>>`
To my surprise I also have to write momentum.bf += &(&gradient.bf * &gradient.bf);
instead of momentum.bf += &gradient.bf * &gradient.bf;
more or less the same error as above (trying to do a scalar operation). All variables are Array1<f32>
Do I lack some understanding of references Rust?
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.
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.
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-examples and 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.
@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 :)
Activity
matzebond commentedon Sep 3, 2019
To my surprise I also have to write
momentum.bf += &(&gradient.bf * &gradient.bf);instead of
momentum.bf += &gradient.bf * &gradient.bf;more or less the same error as above (trying to do a scalar operation). All variables are
Array1<f32>Do I lack some understanding of references Rust?
bluss commentedon Sep 4, 2019
hi, we can look at this if you provide example code for the problem or tell us the types of all the incoming variables
matzebond commentedon Sep 4, 2019
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.
bluss commentedon Sep 4, 2019
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
matzebond commentedon Sep 4, 2019
Are you concerned about the amount of code that will get generated?
bluss commentedon Sep 4, 2019
Yes. Maybe there is a way to simplify it somehow.
[-]Inplace operation with map error[/-][+]Additional arithmetic operations/variants[/+]LukeMathWalker commentedon Sep 8, 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.
bluss commentedon Sep 8, 2019
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
bluss commentedon Sep 8, 2019
@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 :)
LukeMathWalker commentedon Sep 8, 2019
I guess what I meant was "unless you strongly feel against it" 👍 I'll contribute to the discussion in #699