Skip to content

support order kwarg in asarray, asanyarray, ndarray.get, tonumpy - #1845

Merged
okuta merged 6 commits into
cupy:masterfrom
grlee77:asarray_w_order
Dec 24, 2018
Merged

okuta merged 6 commits into
cupy:masterfrom
grlee77:asarray_w_order

Conversation

@grlee77

@grlee77 grlee77 commented Nov 29, 2018

Copy link
Copy Markdown
Member

This is a small PR that continues the quest to improve order kwarg support in CuPy (see also #1819 and #1843).

One outstanding question is what to do for non-cupy objects that define __cuda_array_interface__. For now, I chose to ignore the order argument in that case.

@niboshi niboshi self-assigned this Dec 3, 2018
@grlee77

grlee77 commented Dec 7, 2018 •

Copy link
Copy Markdown
Member Author

There is another case I still need to fix: asarray doesn't preserve order for numpy array inputs

import numpy
import cupy

# cupy.asarray on cupy.ndarray input preserves contiguity
cupy.asarray(cupy.empty((16, 16), order='F')).flags
Out[119]: 
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : True

# cupy.asarray on numpy.ndarray input DOES NOT
cupy.asarray(np.empty((16, 16), order='F')).flags
Out[120]: 
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True

# numpy.asarray preserves contiguity
numpy.asarray(numpy.empty((16, 16), order='F')).flags
Out[120]: 
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : True

The Fortran-ordered NumPy array should result in a Fortran ordered CuPy array. This can be done by having array convert order=None to the default value of Kas is done in NumPy.

Another question is whether the .get() method should also respect order? Currently a C-ordered numpy array is returned when the cupy array has Fortran order.

This change results in cupy.asarray(numpy_fortran_ordered_ndarray) giving a Fortran-ordered array
@grlee77

grlee77 commented Dec 8, 2018

Copy link
Copy Markdown
Member Author

@grlee77

grlee77 commented Dec 8, 2018

Copy link
Copy Markdown
Member Author

I just went ahead and added the orders 'C', 'F', 'A' to ndarray.get() and tonumpy. The default was left at 'C' to maintain backwards compatiblity. There is no NumPy equivalent of these, but I think it makes sense to offer the option.

I can split that to its own separate PR if preferred, but thought it may be easier and save CI resources just review multiple ordering-related things together.

@grlee77 grlee77 changed the title support order kwarg in asarray and asanyarray support order kwarg in asarray, asanyarray, ndarray.get, tonumpy Dec 8, 2018
@okuta okuta added the cat:feature New features/APIs label Dec 24, 2018
@okuta okuta assigned okuta and unassigned niboshi Dec 24, 2018
@okuta okuta added this to the v6.0.0b2 milestone Dec 24, 2018
@okuta

okuta commented Dec 24, 2018

Copy link
Copy Markdown
Member

jenkins, test this please.

@okuta

okuta commented Dec 24, 2018

Copy link
Copy Markdown
Member

Thank you for your PR.

I just went ahead and added the orders 'C', 'F', 'A' to ndarray.get() and tonumpy. The default was left at 'C' to maintain backwards compatiblity. There is no NumPy equivalent of these, but I think it makes sense to offer the option.

I want equivalent behavior. Cloud you send another PR because I will put no-compat label to that PR.

@chainer-ci

Copy link
Copy Markdown
Member

Jenkins CI test (for commit 85155a4, target branch master) succeeded!

@okuta

okuta commented Dec 24, 2018

Copy link
Copy Markdown
Member

LGTM!

@okuta
okuta merged commit f922131 into cupy:master Dec 24, 2018
@grlee77

grlee77 commented Dec 24, 2018

Copy link
Copy Markdown
Member Author

I want equivalent behavior. Cloud you send another PR because I will put no-compat label to that PR.

I am not sure what you are requesting. It looks like you already merged all of the proposed changes?

@okuta

okuta commented Dec 25, 2018

Copy link
Copy Markdown
Member

OK, I understand that this PR contains all.

Then in this section when order_obj is None it looks like order will never be reassigned, so it should keep the default value of 'K':

I misunderstood that this change is not included. This line cares it.

@grlee77
grlee77 deleted the asarray_w_order branch December 31, 2018 17:07
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.

4 participants