Testing Modules

CuPy offers testing utilities to support unit testing. They are under namespace cupy.testing.

Standard Assertions

The assertions have same names as NumPy’s ones. The difference from NumPy is that they can accept both numpy.ndarray and cupy.ndarray.

cupy.testing.assert_allclose Raises an AssertionError if objects are not equal up to desired tolerance.
cupy.testing.assert_array_almost_equal Raises an AssertionError if objects are not equal up to desired precision.
cupy.testing.assert_array_almost_equal_nulp Compare two arrays relatively to their spacing.
cupy.testing.assert_array_max_ulp Check that all items of arrays differ in at most N Units in the Last Place.
cupy.testing.assert_array_equal Raises an AssertionError if two array_like objects are not equal.
cupy.testing.assert_array_list_equal Compares lists of arrays pairwise with assert_array_equal.
cupy.testing.assert_array_less Raises an AssertionError if array_like objects are not ordered by less than.

NumPy-CuPy Consistency Check

The following decorators are for testing consistency between CuPy’s functions and corresponding NumPy’s ones.

cupy.testing.numpy_cupy_allclose Decorator that checks NumPy results and CuPy ones are close.
cupy.testing.numpy_cupy_array_almost_equal Decorator that checks NumPy results and CuPy ones are almost equal.
cupy.testing.numpy_cupy_array_almost_equal_nulp Decorator that checks results of NumPy and CuPy are equal w.
cupy.testing.numpy_cupy_array_max_ulp Decorator that checks results of NumPy and CuPy ones are equal w.
cupy.testing.numpy_cupy_array_equal Decorator that checks NumPy results and CuPy ones are equal.
cupy.testing.numpy_cupy_array_list_equal Decorator that checks the resulting lists of NumPy and CuPy’s one are equal.
cupy.testing.numpy_cupy_array_less Decorator that checks the CuPy result is less than NumPy result.
cupy.testing.numpy_cupy_raises Decorator that checks the NumPy and CuPy throw same errors.

Parameterized dtype Test

The following decorators offer the standard way for parameterized test with respect to single or the combination of dtype(s).

cupy.testing.for_dtypes Decorator for parameterized dtype test.
cupy.testing.for_all_dtypes Decorator that checks the fixture with all dtypes.
cupy.testing.for_float_dtypes Decorator that checks the fixture with all float dtypes.
cupy.testing.for_signed_dtypes Decorator that checks the fixture with signed dtypes.
cupy.testing.for_unsigned_dtypes Decorator that checks the fixture with all dtypes.
cupy.testing.for_int_dtypes Decorator that checks the fixture with integer and optionally bool dtypes.
cupy.testing.for_dtypes_combination Decorator that checks the fixture with a product set of dtypes.
cupy.testing.for_all_dtypes_combination Decorator that checks the fixture with a product set of all dtypes.
cupy.testing.for_signed_dtypes_combination Decorator for parameterized test w.
cupy.testing.for_unsigned_dtypes_combination Decorator for parameterized test w.
cupy.testing.for_int_dtypes_combination Decorator for parameterized test w.

Parameterized order Test

The following decorators offer the standard way to parameterize tests with orders.

cupy.testing.for_orders Decorator to parameterize tests with order.
cupy.testing.for_CF_orders Decorator that checks the fixture with orders ‘C’ and ‘F’.