コード例 #1
0
    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')
コード例 #2
0
 def test_invalid_kernel_name(self):
     with six.assertRaisesRegex(self, ValueError, 'Invalid kernel name'):
         core.ReductionKernel('T x',
                              'T y',
                              'x',
                              'a + b',
                              'y = a',
                              '0',
                              name='1')
コード例 #3
0
ファイル: dia.py プロジェクト: kmatsuura/cupy
    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)
コード例 #4
0
ファイル: misc.py プロジェクト: zhaohb/cupy
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

_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`

    """
    # TODO(Dahlia-Chehata): replace with GPU-based constants.
コード例 #5
0
 def setUp(self):
     self.my_sum = core.ReductionKernel('T x', 'T out', 'x', 'a + b',
                                        'out = a', '0', 'my_sum')
コード例 #6
0
ファイル: add_remove.py プロジェクト: zelo2/cupy
# TODO(okuta): Implement delete


# TODO(okuta): Implement insert


# TODO(okuta): Implement append


# TODO(okuta): Implement resize

_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.