Exemplo n.º 1
0
 def test_remainder(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary('remainder', no_complex=True)
     self.check_raises_with_numpy_input(2, 'remainder')
Exemplo n.º 2
0
 def test_rmod_scalarzero(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_scalarzero_op(operator.mod, swap=True)
Exemplo n.º 3
0
 def test_rtruediv_scalar(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(operator.truediv, swap=True)
Exemplo n.º 4
0
 def test_doubly_broadcasted_truediv(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_doubly_broadcasted_op(operator.truediv)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_floordiv_array(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_array_op(operator.floordiv, no_complex=True)
Exemplo n.º 7
0
 def test_broadcasted_itruediv(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_broadcasted_op(operator.itruediv)
Exemplo n.º 8
0
 def test_doubly_broadcasted_divmod0(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_doubly_broadcasted_op(
             lambda x, y: divmod(x, y)[0])
Exemplo n.º 9
0
 def test_floordiv_scalar(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(operator.floordiv)
Exemplo n.º 10
0
 def test_divide_negative(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary_negative('divide')
Exemplo n.º 11
0
 def test_divmod0_scalar(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(lambda x, y: divmod(x, y)[0])
Exemplo n.º 12
0
 def test_divide(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary('divide')
     self.check_raises_with_numpy_input(2, 'divide')
Exemplo n.º 13
0
 def test_reciprocal(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_unary('reciprocal')
     self.check_raises_with_numpy_input(1, 'reciprocal')
Exemplo n.º 14
0
 def test_remainder_negative(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary_negative_no_complex('remainder')
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
 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)
Exemplo n.º 17
0
 def test_itruediv_array(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_array_op(operator.itruediv)
Exemplo n.º 18
0
 def test_ifloordiv_scalar(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(operator.ifloordiv, no_complex=True)
Exemplo n.º 19
0
 def test_divmod1_array(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_array_op(lambda x, y: divmod(x, y)[1])
Exemplo n.º 20
0
 def test_div_array(self):
     if six.PY3:
         return
     with testing.NumpyError(divide='ignore'):
         self.check_array_array_op(operator.div)
Exemplo n.º 21
0
 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)
Exemplo n.º 22
0
 def test_doubly_broadcasted_div(self):
     if six.PY3:
         return
     with testing.NumpyError(divide='ignore'):
         self.check_array_doubly_broadcasted_op(operator.div)
Exemplo n.º 23
0
 def test_doubly_broadcasted_floordiv(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_doubly_broadcasted_op(operator.floordiv,
                                                no_complex=True)
Exemplo n.º 24
0
 def test_idiv_scalar(self):
     if six.PY3:
         return
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(operator.idiv)
Exemplo n.º 25
0
 def test_mod_scalar(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_scalar_op(operator.mod)
Exemplo n.º 26
0
 def impl(x):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         return getattr(xp, self.func)(x)
Exemplo n.º 27
0
 def test_imod_array(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_array_op(operator.imod)
Exemplo n.º 28
0
    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
Exemplo n.º 29
0
 def test_broadcasted_mod(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_broadcasted_op(operator.mod)
Exemplo n.º 30
0
 def test_fmod_negative(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary_negative_no_complex('fmod')