make GPUArray .imag, .real and .conj() preserve contiguity #151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If a
GPUArray
,g
is Fortran contiguous,g.real
,g.imag
andg.conj()
all currently return C-ordered arrays. The same operations in numpy preserve Fortran ordering.With this PR, those routines return F-ordered arrays if the source array is F-ordered. For C-ordered or non-contiugous arrays, the behaviour will be unchanged.
This PR has some overlap with the existing PR #15, but is more conservative in approach. (I had also considered putting the code setting 'C' vs. 'F' order into
_new_like_me
itself, but wasn't sure if that might cause problems elsewhere).The specific use case I have is in calling a function that only supports Fortran-ordered float32 data and I want to run it on both the real and imaginary components of the input and the recombine them. I already have a Fortran-ordered gpu array,
g
, and would like to be able to call it asout = kernel_func(g.real, ...) + 1j*kernel_func(g.imag, ...)
. I realize this involves some copying of device arrays behind the scenes, but that overhead is relatively small in my application. Currently this approach fails because the real and imaginary components returned do not respect the ordering of the source array. After this PR, it works as expected.The second commit here is independent of the above and just adds an
order
kwarg toreshape
. I think this is preferable to the approach taken in #15 where the linear at 5ea4c97#diff-c6f20a28105688a11d8983cd1fce702cR642 seems to assume a 2D shape.