def ones_like(array, backend=None): if backend is None: backend = array.backend if backend == 'opencl': import pyopencl.array as gpuarray out = 1 + gpuarray.zeros_like(array.dev) elif backend == 'cuda': import pycuda.gpuarray as gpuarray out = gpuarray.ones_like(array.dev) else: out = np.ones_like(array.dev) return wrap_array(out, backend)
def ones_like(array, backend='cython'): if backend == 'opencl': import pyopencl.array as gpuarray dev_array = 1 + gpuarray.zeros_like(array) elif backend == 'cuda': import pycuda.gpuarray as gpuarray dev_array = gpuarray.ones_like(array) else: return Array(np.ones_like(array)) wrapped_array = Array() wrapped_array.set_dev_array(dev_array) return wrapped_array