def to_cudandarray(x):
 if (not isinstance(x, pycuda.gpuarray.GPUArray)):
  raise ValueError('We can transfer only pycuda.gpuarray.GPUArray to CudaNdarray')
 elif (x.dtype != 'float32'):
  raise ValueError('CudaNdarray support only float32')
 else:
  strides = [1]
  for i in x.shape[::(-1)][:(-1)]:
   strides.append((strides[(-1)] * i))
  strides = tuple(strides[::(-1)])
  ptr = int(x.gpudata)
  z = cuda.from_gpu_pointer(ptr, x.shape, strides, x)
  return z

def to_cudandarray ( x ) : if ( not isinstance ( x , pycuda . gpuarray . GPUArray ) ) : raise ValueError ( 'We can transfer only pycuda.gpuarray.GPUArray to CudaNdarray' ) elif ( x . dtype != 'float32' ) : raise ValueError ( 'CudaNdarray support only float32' ) else : strides = [ 1 ] for i in x . shape [ : : ( - 1 ) ] [ : ( - 1 ) ] : strides . append ( ( strides [ ( - 1 ) ] * i ) ) strides = tuple ( strides [ : : ( - 1 ) ] ) ptr = int ( x . gpudata ) z = cuda . from_gpu_pointer ( ptr , x . shape , strides , x ) return z
take a pycuda .