def test_vdot(self, xp, dtype): a = testing.shaped_arange((5, ), xp, dtype) b = testing.shaped_reverse_arange((5, ), xp, dtype) return xp.vdot(a, b)
def test_reversed_inner(self, xp, dtype): a = testing.shaped_arange((5, ), xp, dtype)[::-1] b = testing.shaped_reverse_arange((5, ), xp, dtype)[::-1] return xp.inner(a, b)
def test_copysign_combination(self, xp, dtype_a, dtype_b): a = testing.shaped_arange((2, 3), xp, dtype_a) b = testing.shaped_reverse_arange((2, 3), xp, dtype_b) return xp.copysign(a, b)
def test_nextafter_combination(self, xp, dtype_a, dtype_b): a = testing.shaped_arange((2, 3), xp, dtype_a) # skip 0 because cupy (may) handle denormals differently (-ftz=true) a[a == 0] = 1 b = testing.shaped_reverse_arange((2, 3), xp, dtype_b) return xp.nextafter(a, b)
def check_binary(self, name, xp, dtype, no_bool=False): if no_bool and numpy.dtype(dtype).char == '?': return numpy.int_(0) a = testing.shaped_arange((2, 3), xp, dtype) b = testing.shaped_reverse_arange((2, 3), xp, dtype) return getattr(xp, name)(a, b)
def check_binary(self, name, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) b = testing.shaped_reverse_arange((2, 3), xp, dtype) return getattr(xp, name)(a, b)
def test_copyto_where(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) b = testing.shaped_reverse_arange((2, 3, 4), xp, dtype) c = testing.shaped_arange((2, 3, 4), xp, '?') xp.copyto(a, b, where=c) return a
def test_real_setter(self, xp, dtype): x = testing.shaped_arange((2, 3), xp, dtype) x.real = testing.shaped_reverse_arange((2, 3), xp, dtype).real return x
def test_imag_setter_raise(self, dtype): for xp in (numpy, cupy): x = testing.shaped_arange((2, 3), xp, dtype) with pytest.raises(TypeError): x.imag = testing.shaped_reverse_arange((2, 3), xp, dtype)
def test_imag_setter_non_contiguous(self, xp, dtype): x = testing.shaped_arange((2, 3, 2), xp, dtype).transpose(0, 2, 1) x.imag = testing.shaped_reverse_arange((2, 2, 3), xp, dtype).real return x
# y = xp.asarray(y) # y[y == numpy.inf] = numpy.nan # y[y == -numpy.inf] = numpy.nan return y @testing.gpu @testing.parameterize(*( testing.product({ # TODO(unno): boolean subtract causes DeprecationWarning in numpy>=1.13 'arg1': [testing.shaped_arange((2, 3), numpy, dtype=d) for d in all_types] + [0, 0.0, 2, 2.0], 'arg2': [ testing.shaped_reverse_arange((2, 3), numpy, dtype=d) for d in all_types ] + [0, 0.0, 2, 2.0], 'name': ['add', 'multiply', 'power', 'subtract'], }) + testing.product({ 'arg1': [numpy.array([-3, -2, -1, 1, 2, 3], dtype=d) for d in negative_types] + [0, 0.0, 2, 2.0, -2, -2.0], 'arg2': [numpy.array([-3, -2, -1, 1, 2, 3], dtype=d) for d in negative_types] + [0, 0.0, 2, 2.0, -2, -2.0], 'name': ['divide', 'true_divide', 'subtract'], }))) class TestArithmeticBinary(ArithmeticBinaryBase, unittest.TestCase): def test_binary(self): self.use_dtype = False