Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replacement for numpy.core.umath_tests.inner1d? #10815

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

Closed
lesteve opened this issue Mar 28, 2018 · 3 comments
Closed

Replacement for numpy.core.umath_tests.inner1d? #10815

lesteve opened this issue Mar 28, 2018 · 3 comments

Comments

@lesteve
Copy link
Contributor

lesteve commented Mar 28, 2018

The scikit-learn Travis build using the numpy dev wheel started failing two days ago with the error (see for example this one):

from numpy.core.umath_tests import inner1d
ModuleNotFoundError: No module named 'numpy.core.umath_tests'

This is due to fbb29df#diff-33315af1a22893e97676ee134db5ce1c which renamed compiled modules in numpy.core.

IIUC inner1d was kind of private and we were not meant to use it. What would you suggest is a good replacement for inner1d(arr1, arr2)? I found that np.einsum('...i,..i', arr1, arr2) seemed to be doing something close in our uses cases (arr1 is of shape (p,) and arr2 of shape (n, p) in all our tests) but maybe there is a better replacement?

@jaimefrio
Copy link
Member

If that's all the broadcasting you need, I think np.dot(arr2, arr1) would be the better alternative, as you may get parallelization from the BLAS library. np.einsum may use SIMD if possible, so it is likely also faster than inner1d, and may come up on top of np.dot if it can avoid making copies of the arrays.

@lesteve
Copy link
Contributor Author

lesteve commented Mar 28, 2018

I think np.dot(arr2, arr1) would be the better alternative

Good point, I did not think of that! Thanks a lot for the details!

@lesteve lesteve closed this as completed Mar 28, 2018
@lesteve
Copy link
Contributor Author

lesteve commented Mar 28, 2018

Actually, sometimes we have both arr1 and arr2 of the same shape i.e. (n, p) so I guess np.einsum is the only solution. Edit: actually (arr1 * arr2).sum(axis=1) seems to do the job and reads simpler to my non einsum expert eyes.

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

No branches or pull requests

2 participants