Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dot product is only a valid call for ndarray::Array2 #1439

Open
JulianDicken opened this issue Oct 2, 2024 · 1 comment
Open

Dot product is only a valid call for ndarray::Array2 #1439

JulianDicken opened this issue Oct 2, 2024 · 1 comment

Comments

@JulianDicken
Copy link

JulianDicken commented Oct 2, 2024

Dot product is only a valid call for ndarray::Array2 -- even if the ArrayD is of the same dimensions.

use ndarray::prelude::*;
fn main() {
    let mat1 = Array2::from_shape_vec((3, 2), vec![3.0; 6]).unwrap();
    let mat2 = Array2::from_shape_vec((2, 3), vec![1.0; 6]).unwrap();
    let dot = mat1.dot(&mat2);
}

works, while

use ndarray::prelude::*;
fn main() {
    let mat1 = ArrayD::from_shape_vec(vec![3, 2], vec![3.0; 6]).unwrap();
    let mat2 = ArrayD::from_shape_vec(vec![2, 3], vec![1.0; 6]).unwrap();
    let dot = mat1.dot(&mat2);
}

does not
This results in a very opaque compiler error:

overflow evaluating the requirement `&ArrayBase<_, _>: Not`
consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`ndarray-issue`)
required for `&ArrayBase<_, _>` to implement `Not`
127 redundant requirements hidden
required for `&ArrayBase<OwnedRepr<{float}>, Dim<IxDynImpl>>` to implement `Not`

In my opinion this should either give a clearer error message or be a valid call. I am not experienced enough with rust at the moment to suggest a fix myself.

@JamboChen
Copy link

JamboChen commented Oct 3, 2024

It seems the reason is that the Dot trait hasn’t yet been implemented for IxDyn.

image

I’m interested in contributing to this repository, but considering my limited experience with developing crates, I’m hesitant to jump in right away. Additionally, there seem to be various conventions for multiplying vectors/matrices of different shapes, so I believe this requires more discussion. Perhaps we could also look into how numpy.matmul handles these cases for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants