cupy.testing.for_all_dtypes#
- cupy.testing.for_all_dtypes(name='dtype', no_float16=False, no_bool=False, no_complex=False)[源代码][源代码]#
检查所有数据类型的装置的装饰器。
- 参数:
要测试的数据类型:
numpy.complex64``(可选),``numpy.complex128``(可选),``numpy.float16``(可选),``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'),以及 ``numpy.bool_``(可选)。用法如下。此测试夹具检查
cPickle是否成功为各种 dtypes 重建cupy.ndarray。dtype是由装饰器插入的参数。>>> import unittest >>> from cupy import testing >>> class TestNpz(unittest.TestCase): ... ... @testing.for_all_dtypes() ... def test_pickle(self, dtype): ... a = testing.shaped_arange((2, 3, 4), dtype=dtype) ... s = pickle.dumps(a) ... b = pickle.loads(s) ... testing.assert_array_equal(a, b)
通常,我们将此装饰器与检查 NumPy 和 CuPy 之间一致性的装饰器结合使用,例如
cupy.testing.numpy_cupy_allclose()。以下是这样一个例子。>>> import unittest >>> from cupy import testing >>> 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()