Пример #1
0
def astype_without_warning(x, dtype, *args, **kwargs):
    dtype = numpy.dtype(dtype)
    if x.dtype.kind == 'c' and dtype.kind not in ['b', 'c']:
        with testing.assert_warns(numpy.ComplexWarning):
            return x.astype(dtype, *args, **kwargs)
    else:
        return x.astype(dtype, *args, **kwargs)
Пример #2
0
 def test_view_flags_smaller(self, xp, order, shape):
     a = xp.zeros(shape, numpy.int32, order)
     with contextlib.ExitStack() as stack:
         if order == 'F':
             stack.enter_context(testing.assert_warns(DeprecationWarning))
         b = a.view(numpy.int16)
     return b.flags.c_contiguous, b.flags.f_contiguous, b.flags.owndata
Пример #3
0
 def test_scatter_add(self):
     a = cupy.zeros((3, ), dtype=numpy.float32)
     i = cupy.array([1, 1], numpy.int32)
     v = cupy.array([2., 1.], dtype=numpy.float32)
     with testing.assert_warns(DeprecationWarning):
         cupy.scatter_add(a, i, v)
     testing.assert_array_equal(a, cupy.array([0, 3, 0]))
Пример #4
0
    def test_same_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises(accept_error=Exception)
            def dummy_same_error(self, xp):
                raise Exception(self.tbs.get(xp))

        dummy_same_error(self)
Пример #5
0
 def test_free_all_free(self):
     p1 = self.pool.malloc(self.unit * 4)
     ptr1 = p1.ptr
     del p1
     with testing.assert_warns(DeprecationWarning):
         self.pool.free_all_free()
     p2 = self.pool.malloc(self.unit * 4)
     self.assertNotEqual(ptr1, p2.ptr)
Пример #6
0
    def test_both_success(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises()
            def dummy_both_success(self, xp):
                pass

        with self.assertRaises(AssertionError):
            dummy_both_success(self)
Пример #7
0
    def test_numpy_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises()
            def dummy_numpy_error(self, xp):
                if xp is numpy:
                    raise Exception(self.tbs.get(numpy))

        with self.assertRaisesRegex(AssertionError, self.tbs.get(numpy)):
            dummy_numpy_error(self)
Пример #8
0
 def test_free_all_free(self):
     with cupy.cuda.Device(0):
         mem = self.pool.malloc(1).mem
         self.assertIsInstance(mem, memory.BaseMemory)
         self.assertIsInstance(mem, memory.PooledMemory)
         self.assertEqual(self.pool.n_free_blocks(), 0)
         mem.free()
         self.assertEqual(self.pool.n_free_blocks(), 1)
         with testing.assert_warns(DeprecationWarning):
             self.pool.free_all_free()
         self.assertEqual(self.pool.n_free_blocks(), 0)
Пример #9
0
 def test_free_all_free(self):
     with cupy.cuda.Device(0):
         mem = self.pool.malloc(1).mem
         assert isinstance(mem, memory.BaseMemory)
         assert isinstance(mem, memory.PooledMemory)
         assert self.pool.n_free_blocks() == 0
         mem.free()
         assert self.pool.n_free_blocks() == 1
         with testing.assert_warns(DeprecationWarning):
             self.pool.free_all_free()
         assert self.pool.n_free_blocks() == 0
Пример #10
0
    def test_forbidden_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises(accept_error=False)
            def dummy_forbidden_error(self, xp):
                raise Exception(self.tbs.get(xp))

        pattern = re.compile(
            self.tbs.get(cupy) + '.*' + self.tbs.get(numpy), re.S)
        with self.assertRaisesRegex(AssertionError, pattern):
            dummy_forbidden_error(self)
Пример #11
0
 def check_warns(self,
                 a_shape,
                 y_shape=None,
                 rowvar=True,
                 bias=False,
                 ddof=None,
                 xp=None,
                 dtype=None):
     with testing.assert_warns(RuntimeWarning):
         a, y = self.generate_input(a_shape, y_shape, xp, dtype)
         return xp.cov(a, y, rowvar, bias, ddof)
Пример #12
0
    def test_cupy_derived_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises()
            def dummy_cupy_derived_error(self, xp):
                if xp is cupy:
                    raise _Exception1(self.tbs.get(cupy))
                elif xp is numpy:
                    raise _Exception2(self.tbs.get(numpy))

        dummy_cupy_derived_error(self)  # Assert no exceptions
Пример #13
0
    def test_axis_error_index_different_type(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises()
            def dummy_axis_error(self, xp):
                if xp is cupy:
                    raise numpy.AxisError(self.tbs.get(cupy))
                elif xp is numpy:
                    raise IndexError(self.tbs.get(numpy))

        pattern = re.compile(
            self.tbs.get(cupy) + '.*' + self.tbs.get(numpy), re.S)
        with self.assertRaisesRegex(AssertionError, pattern):
            dummy_axis_error(self)
Пример #14
0
    def test_cupy_numpy_different_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises()
            def dummy_cupy_numpy_different_error(self, xp):
                if xp is cupy:
                    raise TypeError(self.tbs.get(cupy))
                elif xp is numpy:
                    raise ValueError(self.tbs.get(numpy))

        # Use re.S mode to ignore new line characters
        pattern = re.compile(
            self.tbs.get(cupy) + '.*' + self.tbs.get(numpy), re.S)
        with self.assertRaisesRegex(AssertionError, pattern):
            dummy_cupy_numpy_different_error(self)
Пример #15
0
    def test_numpy_derived_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises()
            def dummy_numpy_derived_error(self, xp):
                if xp is cupy:
                    raise Exception(self.tbs.get(cupy))
                elif xp is numpy:
                    raise IndexError(self.tbs.get(numpy))

        # NumPy errors may not derive from CuPy errors, i.e. CuPy errors should
        # be at least as explicit as the NumPy error
        pattern = re.compile(
            self.tbs.get(cupy) + '.*' + self.tbs.get(numpy), re.S)
        with self.assertRaisesRegex(AssertionError, pattern):
            dummy_numpy_derived_error(self)
Пример #16
0
    def test_numpy_derived_unaccept_error(self):
        with testing.assert_warns(DeprecationWarning):

            @testing._helper.numpy_cupy_raises(accept_error=ValueError)
            def dummy_numpy_derived_unaccept_error(self, xp):
                if xp is cupy:
                    raise Exception(self.tbs.get(cupy))
                elif xp is numpy:
                    raise ValueError(self.tbs.get(numpy))

        # `Exception` is not derived from `ValueError`, therefore expect an
        # error
        pattern = re.compile(
            self.tbs.get(cupy) + '.*' + self.tbs.get(numpy), re.S)
        with self.assertRaisesRegex(AssertionError, pattern):
            dummy_numpy_derived_unaccept_error(self)
Пример #17
0
    def test_optimize_autosave(self):
        with tempfile.TemporaryDirectory() as directory:
            filepath = directory + '/optimize_params'

            # non-existing file, readonly=True
            with testing.assert_warns(UserWarning):
                with cupyx.optimizing.optimize(path=filepath, readonly=True):
                    cupy.sum(cupy.arange(2))

            # non-existing file, readonly=False
            with cupyx.optimizing.optimize(path=filepath, readonly=False):
                cupy.sum(cupy.arange(4))
            filesize = os.stat(filepath).st_size
            assert 0 < filesize

            # existing file, readonly=True
            with cupyx.optimizing.optimize(path=filepath, readonly=True):
                cupy.sum(cupy.arange(6))
            assert filesize == os.stat(filepath).st_size

            # existing file, readonly=False
            with cupyx.optimizing.optimize(path=filepath, readonly=False):
                cupy.sum(cupy.arange(8))
            assert filesize < os.stat(filepath).st_size
Пример #18
0
 def check_warns(self, *args, **kw):
     with testing.assert_warns(RuntimeWarning):
         return self._check(*args, **kw)
Пример #19
0
 def test_warn_rcond(self, xp, dtype):
     a = testing.shaped_random((3, 3), xp, dtype)
     b = testing.shaped_random((3, ), xp, dtype)
     with testing.assert_warns(FutureWarning):
         return xp.linalg.lstsq(a, b)
Пример #20
0
 def test_bool_empty(self, dtype):
     with testing.assert_warns(DeprecationWarning):
         assert not bool(cupy.array((), dtype=dtype))
Пример #21
0
 def test_shape_none(self):
     with testing.assert_warns(DeprecationWarning):
         a = cupy.ndarray(None)
     assert a.shape == ()
Пример #22
0
 def test_expand_dims_negative2(self, xp):
     a = testing.shaped_arange((2, 3), xp)
     # Too large and too small axis is deprecated in NumPy 1.13
     with testing.assert_warns(DeprecationWarning):
         return xp.expand_dims(a, -4)
Пример #23
0
 def test_adv_setitem(self, xp, dtype):
     a = xp.zeros(self.shape, dtype=dtype)
     with testing.assert_warns(FutureWarning):
         a[self.indexes] = self.value
     return a
Пример #24
0
 def test_invalid_adv_getitem(self):
     for xp in (numpy, cupy):
         a = testing.shaped_arange(self.shape, xp)
         with pytest.raises(IndexError):
             with testing.assert_warns(FutureWarning):
                 a[self.indexes]
Пример #25
0
 def test_adv_getitem(self, xp, dtype):
     with testing.assert_warns(FutureWarning):
         a = testing.shaped_arange(self.shape, xp, dtype)
         return a[self.indexes]
Пример #26
0
 def test_argwhere(self):
     with testing.assert_warns(DeprecationWarning):
         return cupy.nonzero(self.array)
Пример #27
0
 def test_free_all_free_without_malloc(self):
     with cupy.cuda.Device(0):
         # call directly without malloc.
         with testing.assert_warns(DeprecationWarning):
             self.pool.free_all_free()
         self.assertEqual(self.pool.n_free_blocks(), 0)
Пример #28
0
 def test_zeros_scalar_none(self, xp, dtype, order):
     with testing.assert_warns(DeprecationWarning):
         return xp.zeros(None, dtype=dtype, order=order)
Пример #29
0
 def test_none(self):
     with testing.assert_warns(DeprecationWarning):
         assert internal.get_size(None) == ()
Пример #30
0
 def test_empty_scalar_none(self, xp, dtype, order):
     with testing.assert_warns(DeprecationWarning):
         a = xp.empty(None, dtype=dtype, order=order)
     a.fill(0)
     return a