Skip to content

MAINT: use copy=False in a few astype() calls#5909

Merged
jaimefrio merged 3 commits intonumpy:masterfrom
argriffing:linalg-astype-no-copy
May 22, 2015
Merged

MAINT: use copy=False in a few astype() calls#5909
jaimefrio merged 3 commits intonumpy:masterfrom
argriffing:linalg-astype-no-copy

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.

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