-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
ENH: do integer**2. inplace #8896
Conversation
02cbcc4
to
34c7c4d
Compare
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.
Looks good, modulo the one small comment.
numpy/core/src/multiarray/number.c
Outdated
@@ -589,24 +589,24 @@ fast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) | |||
(a1, (PyObject *)a1, fastop); | |||
} | |||
else { | |||
PyArray_Descr *dtype = NULL; | |||
PyObject *res; |
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.
you don't need res
any more.
Actually, a bigger comment after all: why is |
34c7c4d
to
970f4b9
Compare
good question, square should work just fine. |
9657b5b
to
94f224b
Compare
All looks good to me. Any reason not to merge? |
numpy/core/tests/test_umath.py
Outdated
assert_((x**2.00001).dtype is (x**2.0).dtype) | ||
res = x**2.0 | ||
assert_((x**2.00001).dtype is res.dtype) | ||
assert_(res is not x) |
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.
I think I'd like a not np.shares_memory(res, x)
here too - far too easy to break identity while still having a view.
Also a check that x
is still [1, 2, 3]
would do the job
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.
good idea, done
Squaring integer arrays with float argument always casts to double so the squaring itself can be done inplace. Also use square fastop instead of multiply.
94f224b
to
9a2f0fe
Compare
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.
Looks good to me!
Release note? |
this is really minor, not worth a note |
Was thinking it would fit in with the other comments about avoiding temporaries, but fair enough. |
Squaring integer arrays with float argument always casts to double so
the squaring itself can be done inplace.