def to_gpuarray(x, copyif=False):
 if (not isinstance(x, cuda.CudaNdarray)):
  raise ValueError('We can transfer only CudaNdarray to pycuda.gpuarray.GPUArray')
 else:
  size = 1
  c_contiguous = True
  for i in range((x.ndim - 1), (-1), (-1)):
   if (x.shape[i] == 1):
    continue
   if (x._strides[i] != size):
    c_contiguous = False
    break
   size *= x.shape[i]
  if (not c_contiguous):
   if copyif:
    x = x.copy()
   else:
    raise ValueError('We were asked to not copy memory, but the memory is not c contiguous.')
  px = pycuda.gpuarray.GPUArray(x.shape, x.dtype, base=x, gpudata=x.gpudata)
  return px

def to_gpuarray ( x , copyif = False ) : if ( not isinstance ( x , cuda . CudaNdarray ) ) : raise ValueError ( 'We can transfer only CudaNdarray to pycuda.gpuarray.GPUArray' ) else : size = 1 c_contiguous = True for i in range ( ( x . ndim - 1 ) , ( - 1 ) , ( - 1 ) ) : if ( x . shape [ i ] == 1 ) : continue if ( x . _strides [ i ] != size ) : c_contiguous = False break size *= x . shape [ i ] if ( not c_contiguous ) : if copyif : x = x . copy ( ) else : raise ValueError ( 'We were asked to not copy memory, but the memory is not c contiguous.' ) px = pycuda . gpuarray . GPUArray ( x . shape , x . dtype , base = x , gpudata = x . gpudata ) return px
take a cudandarray and return a pycuda .