cupy.testing.for_all_dtypes¶
-
cupy.testing.
for_all_dtypes
(name='dtype', no_float16=False, no_bool=False)[source]¶ Decorator that checks the fixture with all dtypes.
Parameters: dtypes to be tested:
numpy.float16
(optional),numpy.float32
,numpy.float64
,numpy.dtype('b')
,numpy.dtype('h')
,numpy.dtype('i')
,numpy.dtype('l')
,numpy.dtype('q')
,numpy.dtype('B')
,numpy.dtype('H')
,numpy.dtype('I')
,numpy.dtype('L')
,numpy.dtype('Q')
, andnumpy.bool_
(optional).The usage is as follows. This test fixture checks if
cPickle
successfully reconstructscupy.ndarray
for various dtypes.dtype
is an argument inserted by the decorator.>>> import unittest >>> from cupy import testing >>> @testing.gpu ... class TestNpz(unittest.TestCase): ... ... @testing.for_all_dtypes() ... def test_pickle(self, dtype): ... a = testing.shaped_arange((2, 3, 4), dtype=dtype) ... s = six.moves.cPickle.dumps(a) ... b = six.moves.cPickle.loads(s) ... testing.assert_array_equal(a, b)
Typically, we use this decorator in combination with decorators that check consistency between NumPy and CuPy like
cupy.testing.numpy_cupy_allclose()
. The following is such an example.>>> import unittest >>> from cupy import testing >>> @testing.gpu ... class TestMean(unittest.TestCase): ... ... @testing.for_all_dtypes() ... @testing.numpy_cupy_allclose() ... def test_mean_all(self, xp, dtype): ... a = testing.shaped_arange((2, 3), xp, dtype) ... return a.mean()
See also