def test_concatenate_large_2(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) b = testing.shaped_reverse_arange((2, 3, 2), xp, dtype) c = testing.shaped_arange((2, 3, 3), xp, dtype) d = testing.shaped_arange((2, 3, 5), xp, dtype) e = testing.shaped_arange((2, 3, 2), xp, dtype) return xp.concatenate((a, b, c, d, e), axis=-1)
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) @cupy.fuse() def g(x, y): return getattr(cupy, name)(x, y) return g(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_r_9(self, dtype): cp = cuda.cupy a = testing.shaped_arange((3, 4), cp, dtype) b = testing.shaped_reverse_arange((2, 5), cp, dtype) with self.assertRaises(ValueError): cp.r_[a, b]
def test_concatenate_large_4(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) b = testing.shaped_reverse_arange((2, 3, 4), xp, dtype) return xp.concatenate((a, b) * 10, axis=-1)
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 get_numpy(): a = testing.shaped_arange((2, 3, 4), numpy, dtype) b = testing.shaped_reverse_arange((2, 3, 4), numpy, dtype) c = testing.shaped_arange((2, 3, 4), numpy, '?') numpy.copyto(a, b, where=c) return a
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
def test_nextafter_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.nextafter(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_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_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, xp, dtype): x = testing.shaped_arange((2, 3), xp, dtype) x.imag = testing.shaped_reverse_arange((2, 3), xp, dtype) return x
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 check_ipow_array(self, xp, x_type, y_type): a = testing.shaped_arange((2, 3), xp, x_type) b = testing.shaped_reverse_arange((2, 3), xp, y_type) return operator.ipow(a, b)
def test_concatenate2(self, xp, dtype): a = testing.shaped_arange((2, 3, 4), xp, dtype) b = testing.shaped_reverse_arange((2, 3, 2), xp, dtype) c = testing.shaped_arange((2, 3, 3), xp, dtype) return xp.concatenate((a, b, c), axis=-1)
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 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 check_binary_complex(self, name, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) + 1 b = testing.shaped_reverse_arange((2, 3), xp, dtype) + 1 return 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 a, b
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, 0j, 2, 2.0, 2j, True, False], 'arg2': [ testing.shaped_reverse_arange((2, 3), numpy, dtype=d) for d in all_types ] + [0, 0.0, 0j, 2, 2.0, 2j, True, False], '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, 0j, 2, 2.0, 2j, -2, -2.0, -2j, True, False], 'arg2': [numpy.array([-3, -2, -1, 1, 2, 3], dtype=d) for d in negative_types] + [0, 0.0, 0j, 2, 2.0, 2j, -2, -2.0, -2j, True, False], 'name': ['divide', 'true_divide', 'subtract'], }))) class TestArithmeticBinary(ArithmeticBinaryBase, unittest.TestCase): def test_binary(self): self.use_dtype = False
def test_concatenate_axis_none(self, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) b = testing.shaped_reverse_arange((3, 5, 2), xp, dtype) c = testing.shaped_arange((7, ), xp, dtype) return xp.concatenate((a, b, c), axis=None)
def test_r_8(self, xp, dtype): a = testing.shaped_arange((3, 4), xp, dtype) b = testing.shaped_reverse_arange((2, 4), xp, dtype) c = testing.shaped_reverse_arange((1, 4), xp, dtype) return xp.r_[a, b, c]
def check_array_array_op(self, op, xp, x_type, y_type): a = testing.shaped_arange((2, 3), xp, x_type) b = testing.shaped_reverse_arange((2, 3), xp, y_type) return op(a, b)
def test_c_1(self, xp, dtype): a = testing.shaped_arange((4, 2), xp, dtype) b = testing.shaped_reverse_arange((4, 3), xp, dtype) return xp.c_[a, b]
def check_array_array_op(self, op, xp, dtype): a = testing.shaped_arange((2, 3), xp, dtype) b = testing.shaped_reverse_arange((2, 3), xp, dtype) return op(a, b)
def test_c_2(self, xp, dtype): a = testing.shaped_arange((4, 2), xp, dtype) b = testing.shaped_reverse_arange((4, 3), xp, dtype) c = testing.shaped_reverse_arange((4, 1), xp, dtype) return xp.c_[a, b, c]
def check_binary(self, name, xp, dtype, no_bool=False): if no_bool and numpy.dtype(dtype).char == '?': return 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 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_r_9(self, dtype): a = testing.shaped_arange((3, 4), cupy, dtype) b = testing.shaped_reverse_arange((2, 5), cupy, dtype) with self.assertRaises(ValueError): cupy.r_[a, b]
def check_binary(self, name, xp, dtype, no_complex=False): if no_complex and numpy.dtype(dtype).kind == 'c': return dtype(True) a = testing.shaped_arange((2, 3), xp, dtype) b = testing.shaped_reverse_arange((2, 3), xp, dtype) return getattr(xp, name)(a, b)