示例#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')
 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)
示例#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])
示例#9
0
 def test_floordiv_scalar(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(operator.floordiv)
示例#10
0
 def test_divide_negative(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary_negative('divide')
示例#11
0
 def test_divmod0_scalar(self):
     with testing.NumpyError(divide='ignore'):
         self.check_array_scalar_op(lambda x, y: divmod(x, y)[0])
示例#12
0
 def test_divide(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary('divide')
     self.check_raises_with_numpy_input(2, 'divide')
示例#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')
示例#14
0
 def test_remainder_negative(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary_negative_no_complex('remainder')
示例#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)
示例#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)
示例#17
0
 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)
示例#19
0
 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)
示例#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)
 def test_doubly_broadcasted_div(self):
     if six.PY3:
         return
     with testing.NumpyError(divide='ignore'):
         self.check_array_doubly_broadcasted_op(operator.div)
示例#23
0
 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)
示例#25
0
 def test_mod_scalar(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_scalar_op(operator.mod)
示例#26
0
文件: test_ufunc.py 项目: zelo2/cupy
 def impl(x):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         return getattr(xp, self.func)(x)
示例#27
0
 def test_imod_array(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_array_op(operator.imod)
示例#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
示例#29
0
 def test_broadcasted_mod(self):
     with testing.NumpyError(divide='ignore', invalid='ignore'):
         self.check_array_broadcasted_op(operator.mod)
示例#30
0
 def test_fmod_negative(self):
     with testing.NumpyError(divide='ignore'):
         self.check_binary_negative_no_complex('fmod')