cupy.testing.numpy_cupy_allclose(rtol=1e-07, atol=0, err_msg='', verbose=True, name='xp', type_check=True, accept_error=False, sp_name=None, scipy_name=None, contiguous_check=True)[source]

Decorator that checks NumPy results and CuPy ones are close.

  • rtol (float) – Relative tolerance.

  • atol (float) – Absolute tolerance.

  • err_msg (str) – The error message to be printed in case of failure.

  • verbose (bool) – If True, the conflicting values are appended to the error message.

  • name (str) – Argument name whose value is either numpy or cupy module.

  • type_check (bool) – If True, consistency of dtype is also checked.

  • accept_error (bool, Exception or tuple of Exception) – Specify acceptable errors. When both NumPy test and CuPy test raises the same type of errors, and the type of the errors is specified with this argument, the errors are ignored and not raised. If it is True all error types are acceptable. If it is False no error is acceptable.

  • sp_name (str or None) – Argument name whose value is either scipy.sparse or cupyx.scipy.sparse module. If None, no argument is given for the modules.

  • scipy_name (str or None) – Argument name whose value is either scipy or cupyx.scipy module. If None, no argument is given for the modules.

  • contiguous_check (bool) – If True, consistency of contiguity is also checked.

Decorated test fixture is required to return the arrays whose values are close between numpy case and cupy case. For example, this test case checks numpy.zeros and cupy.zeros should return same value.

>>> import unittest
>>> from cupy import testing
>>> @testing.gpu
... class TestFoo(unittest.TestCase):
...     @testing.numpy_cupy_allclose()
...     def test_foo(self, xp):
...         # ...
...         # Prepare data with xp
...         # ...
...         xp_result = xp.zeros(10)
...         return xp_result