Hi Eli, On Fri, 29 Jul 2011 17:48:23 -0700, "Eli Stevens (Gmail)" <[email protected]> wrote: > Thanks for the pointer. This is what we've generalized out of that: > > def numpy3d_to_array(np_array, order=None): > import pycuda.autoinit > from pycuda.driver import Array, ArrayDescriptor3D, Memcpy3D, > dtype_to_array_format > > if order is None: > order = 'C' if np_array.strides[0] > np_array.strides[2] else 'F' > > if order.upper() == 'C': > d, h, w = np_array.shape > elif order.upper() == "F": > w, h, d = np_array.shape > else: > raise LogicError, "order must be either F or C" > > descr = ArrayDescriptor3D() > descr.width = w > descr.height = h > descr.depth = d > descr.format = dtype_to_array_format(np_array.dtype) > descr.num_channels = 1 > descr.flags = 0 > > device_array = Array(descr) > > copy = Memcpy3D() > copy.set_src_host(np_array) > copy.set_dst_array(device_array) > copy.width_in_bytes = copy.src_pitch = np_array.strides[1] > copy.src_height = copy.height = h > copy.depth = d > > copy() > > return device_array > > Is this something that we could submit a patch with? Seems like it > could be useful in the pycuda lib.
If you could bring this and pyucda.driver.matrix_to_array into
numpy_to_array, I think that would be *very* useful. We'd then deprecate
matrix_to_array and implement it in terms of the new function.
Unrelatedly, ary.flags.{f,c}_contiguous are more reliable checks for
contiguity.
Andreas
pgpPLmKnULf8b.pgp
Description: PGP signature
_______________________________________________ PyCUDA mailing list [email protected] http://lists.tiker.net/listinfo/pycuda
