-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
MAINT: use copy=False in a few astype() calls #5909
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
Conversation
@@ -1749,7 +1750,8 @@ def det(a): | |||
_assertNdSquareness(a) | |||
t, result_t = _commonType(a) | |||
signature = 'D->D' if isComplexType(t) else 'd->d' | |||
return _umath_linalg.det(a, signature=signature).astype(result_t) | |||
r = _umath_linalg.det(a, signature=signature) | |||
return r.astype(result_t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you miss the copy=False
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no copy=False
for astype
of a numpy scalar, I think.
>>> import numpy as np
>>> np.float64(42).astype(float)
42.0
>>> np.float64(42).astype(float, copy=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: astype() takes no keyword arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see... There also seem to be tests that would catch if someone tried to introduce that optimization in the future, so I guess it is OK.
Perhaps it is worth a comment? What about branching on np.isscalar(r)
?
OK I've added this in the most recent commit. |
MAINT: use copy=False in a few astype() calls
Merged, thanks! |
This takes numpygh-5909 a little further.
This is like scikit-learn/scikit-learn#4573. I wasn't able to see any quantifiable speed or memory improvements.