def test_remainder(self): with testing.NumpyError(divide='ignore'): self.check_binary('remainder', no_complex=True) self.check_raises_with_numpy_input(2, 'remainder')
def test_rmod_scalarzero(self): with testing.NumpyError(divide='ignore', invalid='ignore'): self.check_array_scalarzero_op(operator.mod, swap=True)
def test_rtruediv_scalar(self): with testing.NumpyError(divide='ignore'): self.check_array_scalar_op(operator.truediv, swap=True)
def test_doubly_broadcasted_truediv(self): with testing.NumpyError(divide='ignore', invalid='ignore'): self.check_array_doubly_broadcasted_op(operator.truediv)
def test_doubly_broadcasted_divmod1(self): with testing.NumpyError(divide='ignore'): self.check_array_doubly_broadcasted_op( lambda x, y: divmod(x, y)[1], no_complex=True)
def test_floordiv_array(self): with testing.NumpyError(divide='ignore'): self.check_array_array_op(operator.floordiv, no_complex=True)
def test_broadcasted_itruediv(self): with testing.NumpyError(divide='ignore'): self.check_array_broadcasted_op(operator.itruediv)
def test_doubly_broadcasted_divmod0(self): with testing.NumpyError(divide='ignore'): self.check_array_doubly_broadcasted_op( lambda x, y: divmod(x, y)[0])
def test_floordiv_scalar(self): with testing.NumpyError(divide='ignore'): self.check_array_scalar_op(operator.floordiv)
def test_divide_negative(self): with testing.NumpyError(divide='ignore'): self.check_binary_negative('divide')
def test_divmod0_scalar(self): with testing.NumpyError(divide='ignore'): self.check_array_scalar_op(lambda x, y: divmod(x, y)[0])
def test_divide(self): with testing.NumpyError(divide='ignore'): self.check_binary('divide') self.check_raises_with_numpy_input(2, 'divide')
def test_reciprocal(self): with testing.NumpyError(divide='ignore', invalid='ignore'): self.check_unary('reciprocal') self.check_raises_with_numpy_input(1, 'reciprocal')
def test_remainder_negative(self): with testing.NumpyError(divide='ignore'): self.check_binary_negative_no_complex('remainder')
def test_rdivmod1_scalar(self): with testing.NumpyError(divide='ignore'): self.check_array_scalar_op(lambda x, y: divmod(x, y)[1], swap=True, no_complex=True)
def test_norm(self, xp, dtype): a = testing.shaped_arange(self.shape, xp, dtype) with testing.NumpyError(divide='ignore'): return xp.linalg.norm(a, self.ord, self.axis, self.keepdims)
def test_itruediv_array(self): with testing.NumpyError(divide='ignore'): self.check_array_array_op(operator.itruediv)
def test_ifloordiv_scalar(self): with testing.NumpyError(divide='ignore'): self.check_array_scalar_op(operator.ifloordiv, no_complex=True)
def test_divmod1_array(self): with testing.NumpyError(divide='ignore'): self.check_array_array_op(lambda x, y: divmod(x, y)[1])
def test_div_array(self): if six.PY3: return with testing.NumpyError(divide='ignore'): self.check_array_array_op(operator.div)
def test_broadcasted_ifloordiv(self): if '1.16.1' <= numpy.lib.NumpyVersion(numpy.__version__) < '1.18.0': self.skipTest("NumPy Issue #12927") with testing.NumpyError(divide='ignore'): self.check_array_broadcasted_op(operator.ifloordiv, no_complex=True)
def test_doubly_broadcasted_div(self): if six.PY3: return with testing.NumpyError(divide='ignore'): self.check_array_doubly_broadcasted_op(operator.div)
def test_doubly_broadcasted_floordiv(self): with testing.NumpyError(divide='ignore'): self.check_array_doubly_broadcasted_op(operator.floordiv, no_complex=True)
def test_idiv_scalar(self): if six.PY3: return with testing.NumpyError(divide='ignore'): self.check_array_scalar_op(operator.idiv)
def test_mod_scalar(self): with testing.NumpyError(divide='ignore', invalid='ignore'): self.check_array_scalar_op(operator.mod)
def impl(x): with testing.NumpyError(divide='ignore', invalid='ignore'): return getattr(xp, self.func)(x)
def test_imod_array(self): with testing.NumpyError(divide='ignore', invalid='ignore'): self.check_array_array_op(operator.imod)
def check_binary(self, xp): arg1 = self.arg1 arg2 = self.arg2 np1 = numpy.asarray(arg1) np2 = numpy.asarray(arg2) dtype1 = np1.dtype dtype2 = np2.dtype if self.name == 'power': # TODO(niboshi): Fix this: power(0, 1j) # numpy => 1+0j # cupy => 0j if dtype2 in complex_types and (np1 == 0).any(): return xp.array(True) # TODO(niboshi): Fix this: xp.power(0j, 0) # numpy => 1+0j # cupy => 0j c_arg1 = dtype1 in complex_types if c_arg1 and (np1 == 0j).any() and (np2 == 0).any(): return xp.array(True) # TODO(niboshi): Fix this: xp.add(0j, xp.array([2.], 'f')).dtype # numpy => complex64 # cupy => complex128 if isinstance(arg1, complex): if dtype2 in (numpy.float16, numpy.float32): return xp.array(True) if isinstance(arg1, numpy.ndarray): arg1 = xp.asarray(arg1) if isinstance(arg2, numpy.ndarray): arg2 = xp.asarray(arg2) # NumPy>=1.13.0 does not support subtraction between booleans # TODO(niboshi): Write a separate test to check both NumPy and CuPy # raise TypeError. if testing.numpy_satisfies('>=1.13.0') and self.name == 'subtract': if dtype1 == numpy.bool_ and dtype2 == numpy.bool_: return xp.array(True) func = getattr(xp, self.name) with testing.NumpyError(divide='ignore'): with numpy.warnings.catch_warnings(): numpy.warnings.filterwarnings('ignore') if self.use_dtype: y = func(arg1, arg2, dtype=self.dtype) else: y = func(arg1, arg2) # TODO(niboshi): Fix this. If rhs is a Python complex, # numpy returns complex64 # cupy returns complex128 if xp is cupy and isinstance(arg2, complex): if dtype1 in (numpy.float16, numpy.float32): y = y.astype(numpy.complex64) # NumPy returns different values (nan/inf) on division by zero # depending on the architecture. # As it is not possible for CuPy to replicate this behavior, we ignore # the difference here. if self.name in ('floor_divide', 'remainder'): if y.dtype in (float_types + complex_types) and (np2 == 0).any(): y = xp.asarray(y) y[y == numpy.inf] = numpy.nan y[y == -numpy.inf] = numpy.nan return y
def test_broadcasted_mod(self): with testing.NumpyError(divide='ignore', invalid='ignore'): self.check_array_broadcasted_op(operator.mod)
def test_fmod_negative(self): with testing.NumpyError(divide='ignore'): self.check_binary_negative_no_complex('fmod')