Repository navigation
Add the order kwarg to cupy.reshape and the underlying ndarray method - #1843
Conversation
|
Here is a quick benchmarks in an Ipython indicating that the overhead is likely only ~1 microsecond when applying order='F' to a fortran-ordered array vs. applying order='C' to a C-ordered array. This overhead is substantially less than the overhead of making a copy (at least for the moderate array size tested here). |
niboshi
left a comment
There was a problem hiding this comment.
Thank you for the PR! Please check the review.
| self.assertFalse(a.flags.c_contiguous) | ||
| self.assertTrue(a.flags.f_contiguous) | ||
|
|
||
| a = a.reshape(1, 6, 1, order='F') |
There was a problem hiding this comment.
Shouldn't it be b =? Or is it intended?
There was a problem hiding this comment.
I have replaced these test cases with a more thorough set of tests.
A few of the new test cases with order = 'A' required the following change to get the same behavior as numpy:
if order_char == 'A':
if self._f_contiguous:
order_char = 'F'
else:
order_char = 'C'to
if order_char == 'A':
if self._f_contiguous and not self._c_contiguous:
order_char = 'F'
else:
order_char = 'C'f6f5919 to
791ad15
Compare
|
Jenkins, test this please. |
|
Jenkins CI test (for commit 791ad15, target branch master) failed with status FAILURE. |
|
Could you check test failure? |
|
I am traveling and don't have access to a GPU for the next couple of days, but will take a look later in the week. |
lowercase 'c', 'f', 'a' are also allowed
order='K' has not yet been implemented
|
Okay, this seems to be an issue with different behavior in older numpy. If I mark the test as requiring numpy >= 1.12 it should work. simple example: import numpy as np
np.arange(6).reshape((1, 6, 1)).flagsThis will show True for C contiguous, but False for F contiguous in NumPy 1.9-1.11, but True for both in NumPy 1.12+. Having both be True seems correct to me, so I think we just need to require 1.12+ on that test. |
A C-contiguous array with shape (1, 6, 1) has True for both F-contiguous and C-contiguous flags only in NumPy>=1.12.
791ad15 to
04a8cb3
Compare
|
This is ready to try the CI again. (I assume a core team member needs to request from Jenkins?) |
|
Thanks! |
|
Jenkins CI test (for commit 04a8cb3, target branch master) failed with status FAILURE. |
|
Thanks, LGTM! |
order kwarg to cupy.reshape and the underlying ndarray method
This PR implements a simple means to support the
orderkwarg in ndarray'sreshapemethod.namely, the trick used here is that:
is equivalent to:
Various reshape test cases were duplicated for Fortran order to verify that this is indeed the case.
This transpose-based implementation probably has slight overhead vs. a lower-level implementation, but is considerably simpler and seems to have fairly small overhead. This is probably because transpose is fast as it returns a view rather than a copy.