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

Type signature of numpy::innner does not cover all cases #284

Closed
lmk0724 opened this issue Mar 5, 2022 · 3 comments · Fixed by #285
Closed

Type signature of numpy::innner does not cover all cases #284

lmk0724 opened this issue Mar 5, 2022 · 3 comments · Fixed by #285
Labels

Comments

@lmk0724
Copy link

lmk0724 commented Mar 5, 2022

when I use numpy::inner(), I face the following problem,
float64' object cannot be converted to 'PyArray<T, D>

here is my code
let array = numpy::pyarray![py, 1.0, 2.0, 3.0]; let inner: &numpy::PyArray0::<_> = numpy::inner(array, array).unwrap(); println!("{}",inner.item());

@adamreichold adamreichold changed the title the type of pyarray is f64 in numpy::innner() Type signature of numpy::innner does not cover all cases Mar 5, 2022
@adamreichold
Copy link
Member

adamreichold commented Mar 5, 2022

I can confirm that this issue happens with arrays of element type f64, but not with arrays of element type i32, i.e. NumPy's effective type signature is more dynamic than our

fn inner<'py, T, DIN1, DIN2, DOUT>(
    array1: &'py PyArray<T, DIN1>,
    array2: &'py PyArray<T, DIN2>,
) -> PyResult<&'py PyArray<T, DOUT>>;

and we need to figure out how to extend this to cover this case. (While I understand that it is not a problem for Python itself, this inconsistency seems somewhat unfortunate.)

@pickanameforlove As a workaround, I think you should be able to use ndarray's ArrayBase::dot to compute the inner product of two vectors as long as they are real-valued. (I would always recommend to use ndarray functions if they get the job done.)

@lmk0724
Copy link
Author

lmk0724 commented Mar 5, 2022

Ok, Thank you

@adamreichold
Copy link
Member

This will require a breaking change in our API and therefore will not be part of a 0.16.x bugfix release. Sorry for that.

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

Successfully merging a pull request may close this issue.

2 participants