pycuda icon indicating copy to clipboard operation
pycuda copied to clipboard

`empty_like` ignores memory-order

Open untom opened this issue 10 years ago • 1 comments

Consider:

x = np.random.normal(size=(3, 5)).astype(np.float64, order="F")
x_gpu = gpuarray.to_gpu(x)
y_gpu = gpuarray.empty_like(x_gpu)
x_gpu.flags.c_contiguous == y_gpu.flags.c_contiguous   # gives "False"

I'm not very familiar with the ArrayFlags mechanism. It seems to me that the problem is that empty_like doesn't set the strides argument of the GPUArray-constructor. But I don't know the repercussions of doing this, so I didn't send a PR.

untom avatar Mar 15 '15 21:03 untom

Matching the original strides is not a plausible strategy, since the argument array could be non-contiguous or have negative strides, neither of which would go well in a newly-allocated buffer that matches the argument's shape. Numpy's strategy seems to be to look at the original strides and see if they are more Fortran-like or C-like (increasing or decreasing) and appears to assign strides based on that.

I'd be happy to take a patch that implements a strategy like this. Bonus points if it matches numpy exactly.

inducer avatar Mar 20 '15 23:03 inducer