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
Performance of asarray() when input is already an array #13580
Comments
I think the discussion #11804 is relevant. |
@seberg and I just discussed this: the expected speedup from moving |
This moves all argument parsing into specialized code (unless an error with the arguments itself is found). Especially, the move to C, while also avoiding any kwarg parsing in the case of e.g. `np.asarray(arr)` means that such simple call speed up by more than a factor of 3. That optimization is still very small, but assuming that it is called a lot (and occasioanlly in tight loops) it may be worth it. Closes numpygh-13580
This has been fixed by my new argparsing code and moving these Using |
That's great news, thanks @seberg! |
I have noticed that
np.asarray(x)
andnp.asarray(x, float)
have pretty big overheads when the input,x
, is already a float array. One could perhaps check whether that is already the case, immediately returningx
if possible. The additional check would have a negligible cost in the case where a conversion is needed (because the conversion e.g. from ax
that's a list is much slower than anything else).Reproducing code example:
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: