def setUp(self): if self.stream == 'null': self.stream = cupy.cuda.Stream.null elif self.stream == 'new': self.stream = cupy.cuda.Stream() self.my_sum = _core.ReductionKernel('T x', 'T out', 'x', 'a + b', 'out = a', '0', 'my_sum')
def getnnz(self, axis=None): """Returns the number of stored values, including explicit zeros. Args: axis: Not supported yet. Returns: int: The number of stored values. """ if axis is not None: raise NotImplementedError( 'getnnz over an axis is not implemented for DIA format') m, n = self.shape nnz = _core.ReductionKernel( 'int32 offsets, int32 m, int32 n', 'int32 nnz', 'offsets > 0 ? min(m, n - offsets) : min(m + offsets, n)', 'a + b', 'nnz = a', '0', 'dia_nnz')(self.offsets, m, n) return int(nnz)
import cupy import cupyx.scipy.fft from cupy import _core from cupy._core import _routines_math as _math from cupy._core import fusion from cupy.lib import stride_tricks import numpy _dot_kernel = _core.ReductionKernel('T x1, T x2', 'T y', 'x1 * x2', 'a + b', 'y = a', '0', 'dot_product') def _choose_conv_method(in1, in2, mode): if in1.ndim != 1 or in2.ndim != 1: raise NotImplementedError('Only 1d inputs are supported currently') if in1.dtype.kind in 'bui' or in2.dtype.kind in 'bui': return 'direct' if _fftconv_faster(in1, in2, mode): return 'fft' return 'direct' def _fftconv_faster(x, h, mode): """ .. seealso:: :func: `scipy.signal._signaltools._fftconv_faster`
data are repeated in the order that they are stored in memory. .. seealso:: :func:`numpy.resize` """ if numpy.isscalar(a): return cupy.full(new_shape, a) a = cupy.asarray(a) if a.size == 0: return cupy.zeros(new_shape, dtype=a.dtype) out = cupy.empty(new_shape, a.dtype) _resize_kernel(a, a.size, out) return out _first_nonzero_krnl = _core.ReductionKernel('T data, int64 len', 'int64 y', 'data == T(0) ? len : _j', 'min(a, b)', 'y = a', 'len', 'first_nonzero') def trim_zeros(filt, trim='fb'): """Trim the leading and/or trailing zeros from a 1-D array or sequence. Returns the trimmed array Args: filt(cupy.ndarray): Input array trim(str, optional): 'fb' default option trims the array from both sides. 'f' option trim zeros from front. 'b' option trim zeros from back.