コード例 #1
0
from cupy import reduction


def all(a, axis=None, out=None, keepdims=False):
    return _all(a, axis=axis, out=out, keepdims=keepdims)


def any(a, axis=None, out=None, keepdims=False):
    return _any(a, axis=axis, out=out, keepdims=keepdims)


_all = reduction.create_reduction_func(
    'cupy_all', ('?->?', 'B->?', 'h->?', 'H->?', 'i->?', 'I->?', 'l->?',
                 'L->?', 'q->?', 'Q->?', 'e->?', 'f->?', 'd->?'),
    ('in0', 'a & b', 'out0 = a', 'bool'), 'true', '')

_any = reduction.create_reduction_func(
    'cupy_any', ('?->?', 'B->?', 'h->?', 'H->?', 'i->?', 'I->?', 'l->?',
                 'L->?', 'q->?', 'Q->?', 'e->?', 'f->?', 'd->?'),
    ('in0', 'a | b', 'out0 = a', 'bool'), 'false', '')
コード例 #2
0
ファイル: truth.py プロジェクト: hokuto-k/chainer
from cupy import reduction


def all(a, axis=None, out=None, keepdims=False):
    return _all(a, axis=axis, out=out, keepdims=keepdims)


def any(a, axis=None, out=None, keepdims=False):
    return _any(a, axis=axis, out=out, keepdims=keepdims)


_all = reduction.create_reduction_func(
    'cupy_all',
    ('?->?', 'B->?', 'h->?', 'H->?', 'i->?', 'I->?', 'l->?', 'L->?',
     'q->?', 'Q->?', 'e->?', 'f->?', 'd->?'),
    ('in0', 'a & b', 'out0 = a', 'bool'),
    'true', '')


_any = reduction.create_reduction_func(
    'cupy_any',
    ('?->?', 'B->?', 'h->?', 'H->?', 'i->?', 'I->?', 'l->?', 'L->?',
     'q->?', 'Q->?', 'e->?', 'f->?', 'd->?'),
    ('in0', 'a | b', 'out0 = a', 'bool'),
    'false', '')
コード例 #3
0
ファイル: meanvar.py プロジェクト: yanweifu/chainer
def nanmean(a, axis=None, dtype=None, out=None, keepdims=False):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def nanstd(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def nanvar(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def _count_reduce_items(arr, axis):
    items = 1
    for ax in axis:
        items *= arr.shape[ax]
    return items


# TODO(okuta) needs cast
_mean = reduction.create_reduction_func(
    'cupy_mean',
    ['?->d', 'B->d', 'h->d', 'H->d', 'i->d', 'I->d', 'l->d', 'L->d',
     'q->d', 'Q->d',
     ('e->e', (None, None, None, 'float')),
     'f->f', 'd->d'],
    ('in0', 'a + b', 'out0 = a / (_in_ind.size() / _out_ind.size())', None))
コード例 #4
0
ファイル: test_reduction.py プロジェクト: hengck23/chainer
 def setUp(self):
     self.my_int8_sum = reduction.create_reduction_func(
         'my_sum', ('b->b',), ('in0', 'a + b', 'out0 = a', None))
コード例 #5
0
ファイル: count.py プロジェクト: hokuto-k/chainer
from cupy import reduction


def count_nonzero(x):
    """Counts the number of non-zero values in the array.

    Args:
        x (cupy.ndarray): The array for which to count non-zeros.

    Returns:
        int: Number of non-zero values in the array.

    """

    return int(_count_nonzero(x))

_count_nonzero = reduction.create_reduction_func(
    'cupy_count_nonzero',
    ('?->l', 'B->l', 'h->l', 'H->l', 'i->l', 'I->l', 'l->l', 'L->l',
     'q->l', 'Q->l', 'e->l', 'f->l', 'd->l'),
    ('in0', 'a + b', 'out0 = (a != 0)', None), 0)
コード例 #6
0
ファイル: sumprod.py プロジェクト: yanweifu/chainer
def ediff1d(ary, to_end=None, to_begin=None):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def gradient(f, *varargs, **kwargs):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def trapz(y, x=None, dx=1.0, axis=-1):
    # TODO(beam2d): Implement it
    raise NotImplementedError


_sum = reduction.create_reduction_func('cupy_sum', [
    '?->l', 'B->L', 'h->l', 'H->L', 'i->l', 'I->L', 'l->l', 'L->L', 'q->q',
    'Q->Q', ('e->e', (None, None, None, 'float')), 'f->f', 'd->d'
], ('in0', 'a + b', 'out0 = a', None), 0)

_prod = reduction.create_reduction_func('cupy_prod', [
    '?->l', 'B->L', 'h->l', 'H->L', 'i->l', 'I->L', 'l->l', 'L->L', 'q->q',
    'Q->Q', ('e->e', (None, None, None, 'float')), 'f->f', 'd->d'
], ('in0', 'a * b', 'out0 = a', None), 1)
コード例 #7
0
from cupy import reduction


def count_nonzero(x):
    """Counts the number of non-zero values in the array.

    Args:
        x (cupy.ndarray): The array for which to count non-zeros.

    Returns:
        int: Number of non-zero values in the array.

    """

    return int(_count_nonzero(x))


_count_nonzero = reduction.create_reduction_func(
    'cupy_count_nonzero',
    ('?->l', 'B->l', 'h->l', 'H->l', 'i->l', 'I->l', 'l->l', 'L->l', 'q->l',
     'Q->l', 'e->l', 'f->l', 'd->l'), ('in0 != 0', 'a + b', 'out0 = a', None),
    0)
コード例 #8
0
ファイル: sumprod.py プロジェクト: umitanuki/chainer
    # TODO(beam2d): Implement it
    raise NotImplementedError


def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None):
    # TODO(beam2d): Implement it
    raise NotImplementedError


def trapz(y, x=None, dx=1.0, axis=-1):
    # TODO(beam2d): Implement it
    raise NotImplementedError


_sum = reduction.create_reduction_func(
    'cupy_sum',
    ['?->l', 'B->L', 'h->l', 'H->L', 'i->l', 'I->L', 'l->l', 'L->L',
     'q->q', 'Q->Q',
     ('e->e', (None, None, None, 'float')),
     'f->f', 'd->d'],
    ('in0', 'a + b', 'out0 = a', None), 0)


_prod = reduction.create_reduction_func(
    'cupy_prod',
    ['?->l', 'B->L', 'h->l', 'H->L', 'i->l', 'I->L', 'l->l', 'L->L',
     'q->q', 'Q->Q',
     ('e->e', (None, None, None, 'float')),
     'f->f', 'd->d'],
    ('in0', 'a * b', 'out0 = a', None), 1)