Skip to content

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

Merged
merged 3 commits into from
May 22, 2015

Conversation

argriffing
Copy link
Contributor

This is like scikit-learn/scikit-learn#4573. I wasn't able to see any quantifiable speed or memory improvements.

@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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)?

@argriffing
Copy link
Contributor Author

What about branching on np.isscalar(r)?

OK I've added this in the most recent commit.

jaimefrio added a commit that referenced this pull request May 22, 2015
MAINT: use copy=False in a few astype() calls
@jaimefrio jaimefrio merged commit fd94000 into numpy:master May 22, 2015
@jaimefrio
Copy link
Member

Merged, thanks!

eric-wieser added a commit to eric-wieser/numpy that referenced this pull request Nov 9, 2017
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

Successfully merging this pull request may close these issues.

3 participants