Repository navigation
Add order argument to empty_like, zeros_like, etc. - #1819
Conversation
niboshi
left a comment
There was a problem hiding this comment.
Thank you for PR!
Please check my review.
|
|
||
|
|
||
| def empty_like(a, dtype=None): | ||
| def _new_like_order_and_strides(a, dtype, order): |
There was a problem hiding this comment.
There already is a logic for this calculation in ndarray.astype (see the link below).
How about reusing it (some refactoring may be needed)?
Or adding a TODO for that might be okay.
Line 393 in 95d4ba7
There was a problem hiding this comment.
Thanks for pointing out that code! I refactored the Cython code slightly and then used the refactored functions to replace the majority of the code in _new_like_order_and_strides.
There is still a subtle difference in numpy vs. cupy if you pass a non-string argument order in empty_like, etc. At least in NumPy 1.15.1, this raises a warning:
"DeprecationWarning: Non-string object detected for the array ordering. Please pass in 'C', 'F', 'A', or 'K' instead"
whereas this cupy implementation would instead raise an error:
AttributeError: 'int' object has no attribute 'upper'
What do you recommend in this case? (we could do a try/except around the call to upper() and raise a similar warning, but I'm not sure it is worth it or when the warning may change to an error).
There was a problem hiding this comment.
Sorry for late reply. I think an error is more appropriate because we are not deprecating it.
order and stride calculations are split out into separate functions so that they can be reused elsewhere as well. In particular, the same logic is needed for implementing the order option to empty_like, zeros_like, etc.
|
jenkins, test this please |
|
Jenkins CI test (for commit 4876f49, target branch master) succeeded! |
order argument to empty_like, zeros_like, etc.
|
Thank you very much! |
closes #1654