Skip to content

Add order argument to empty_like, zeros_like, etc. - #1819

Merged
niboshi merged 11 commits into
cupy:masterfrom
grlee77:empty_like_w_order
Dec 19, 2018
Merged

niboshi merged 11 commits into
cupy:masterfrom
grlee77:empty_like_w_order

Conversation

@grlee77

@grlee77 grlee77 commented Nov 23, 2018

Copy link
Copy Markdown
Member

closes #1654

@okuta okuta added the cat:feature New features/APIs label Nov 25, 2018

@niboshi niboshi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for PR!
Please check my review.

Comment thread cupy/creation/basic.py Resolved
Comment thread cupy/creation/basic.py


def empty_like(a, dtype=None):
def _new_like_order_and_strides(a, dtype, order):

@niboshi niboshi Nov 29, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

if order_char == 'A':

@grlee77 grlee77 Nov 29, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reply. I think an error is more appropriate because we are not deprecating it.

@niboshi

niboshi commented Dec 17, 2018

Copy link
Copy Markdown
Contributor

jenkins, test this please

@chainer-ci

Copy link
Copy Markdown
Member

Jenkins CI test (for commit 4876f49, target branch master) succeeded!

@niboshi niboshi changed the title add order argument to empty_like, zeros_like, etc. Add order argument to empty_like, zeros_like, etc. Dec 19, 2018
@niboshi

niboshi commented Dec 19, 2018

Copy link
Copy Markdown
Contributor

Thank you very much!

@niboshi
niboshi merged commit aab98a1 into cupy:master Dec 19, 2018
@niboshi niboshi added this to the v6.0.0b2 milestone Dec 19, 2018
@grlee77
grlee77 deleted the empty_like_w_order branch December 31, 2018 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:feature New features/APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: preserve memory layout order in empty_like, etc?

4 participants