def __init__(self, shape, dtype, allocator=drv.mem_alloc, base=None, gpudata=None, strides=None, order="C"): dtype = np.dtype(dtype) try: s = 1 for dim in shape: s *= dim except TypeError: # handle dim-0 ndarrays: if isinstance(shape, np.ndarray): shape = np.asscalar(shape) assert isinstance(shape, numbers.Integral) s = shape shape = (shape,) else: # handle shapes that are ndarrays shape = tuple(shape) if isinstance(s, np.integer): # bombs if s is a Python integer s = np.asscalar(s) if strides is None: if order == "F": strides = _f_contiguous_strides( dtype.itemsize, shape) elif order == "C": strides = _c_contiguous_strides( dtype.itemsize, shape) else: raise ValueError("invalid order: %s" % order) else: # FIXME: We should possibly perform some plausibility # checking on 'strides' here. strides = tuple(strides) self.shape = tuple(shape) self.dtype = dtype self.strides = strides self.mem_size = self.size = s self.nbytes = self.dtype.itemsize * self.size self.allocator = allocator if gpudata is None: if self.size: self.gpudata = self.allocator(self.size * self.dtype.itemsize) else: self.gpudata = None assert base is None else: self.gpudata = gpudata self.base = base self._grid, self._block = splay(self.mem_size)
def __init__(self, backend, shape, iwl, allocator=drv.mem_alloc, base=None, gpudata=None, strides=None, is_trans=False, order="C"): dtype = np.dtype(np.int16) try: size = 1 for dim in shape: size *= dim except TypeError: assert isinstance(shape, (int, long, np.integer)) size = shape shape = (shape, ) if isinstance(size, np.integer): size = np.asscalar(size) if strides is None: if order == "F": strides = _f_contiguous_strides(dtype.itemsize, shape) elif order == "C": strides = _c_contiguous_strides(dtype.itemsize, shape) else: raise ValueError("invalid order: %s" % order) else: strides = tuple(strides) self.backend = backend self.base = base self.shape = shape self.iwl = iwl self.strides = strides self.size = size self.dtype = dtype self.nbytes = dtype.itemsize * size self.allocator = allocator self.is_trans = is_trans if gpudata is None: if size: self.gpudata = allocator(self.nbytes) else: self.gpudata = None assert base is None else: self.gpudata = gpudata
def __init__(self, shape, dtype, allocator=drv.mem_alloc, base=None, gpudata=None, strides=None, order="C"): dtype = np.dtype(dtype) try: s = 1 for dim in shape: s *= dim except TypeError: assert isinstance(shape, (int, long, np.integer)) s = shape shape = (shape, ) if strides is None: if order == "F": strides = _f_contiguous_strides(dtype.itemsize, shape) elif order == "C": strides = _c_contiguous_strides(dtype.itemsize, shape) else: raise ValueError("invalid order: %s" % order) else: # FIXME: We should possibly perform some plausibility # checking on 'strides' here. strides = tuple(strides) self.shape = shape self.dtype = dtype self.strides = strides self.mem_size = self.size = s self.nbytes = self.dtype.itemsize * self.size self.allocator = allocator if gpudata is None: if self.size: self.gpudata = self.allocator(self.size * self.dtype.itemsize) else: self.gpudata = None assert base is None else: self.gpudata = gpudata self.base = base self._grid, self._block = splay(self.mem_size)
def __init__(self, shape, dtype, allocator=drv.mem_alloc, base=None, gpudata=None, strides=None, order="C"): dtype = np.dtype(dtype) try: s = 1 for dim in shape: s *= dim except TypeError: assert isinstance(shape, (int, long, np.integer)) s = shape shape = (shape,) if strides is None: if order == "F": strides = _f_contiguous_strides( dtype.itemsize, shape) elif order == "C": strides = _c_contiguous_strides( dtype.itemsize, shape) else: raise ValueError("invalid order: %s" % order) else: # FIXME: We should possibly perform some plausibility # checking on 'strides' here. strides = tuple(strides) self.shape = shape self.dtype = dtype self.strides = strides self.mem_size = self.size = s self.nbytes = self.dtype.itemsize * self.size self.allocator = allocator if gpudata is None: if self.size: self.gpudata = self.allocator(self.size * self.dtype.itemsize) else: self.gpudata = None assert base is None else: self.gpudata = gpudata self.base = base self._grid, self._block = splay(self.mem_size)
def __init__(self, backend, shape, iwl, allocator=drv.mem_alloc, base=None, gpudata=None, strides=None, is_trans=False, order="C"): dtype = np.dtype(np.int16) try: size = 1 for dim in shape: size *= dim except TypeError: assert isinstance(shape, (int, long, np.integer)) size = shape shape = (shape,) if isinstance(size, np.integer): size = np.asscalar(size) if strides is None: if order == "F": strides = _f_contiguous_strides(dtype.itemsize, shape) elif order == "C": strides = _c_contiguous_strides(dtype.itemsize, shape) else: raise ValueError("invalid order: %s" % order) else: strides = tuple(strides) self.backend = backend self.base = base self.shape = shape self.iwl = iwl self.strides = strides self.size = size self.dtype = dtype self.nbytes = dtype.itemsize * size self.allocator = allocator self.is_trans = is_trans if gpudata is None: if size: self.gpudata = allocator(self.nbytes) else: self.gpudata = None assert base is None else: self.gpudata = gpudata