Arithmetic test: Avoid subtraction between booleans
import itertools
import numpy
+import pkg_resources
import unittest
import cupy
from cupy import testing
+def numpy_satisfies(version_range):
+ """Returns True if numpy version satisfies the specified criteria."""
+ spec = 'numpy{}'.format(version_range)
+ try:
+ pkg_resources.require(spec)
+ except pkg_resources.VersionConflict:
+ return False
+ return True
+
+
float_types = [numpy.float16, numpy.float32, numpy.float64]
complex_types = [numpy.complex, numpy.complex64, numpy.complex128]
signed_int_types = [numpy.int8, numpy.int16, numpy.int32, numpy.int64]
@@ -180,6 +191,16 @@ class TestArithmeticBinary(unittest.TestCase):
if isinstance(arg2, numpy.ndarray):
arg2 = xp.asarray(arg2)
+ # NumPy>=1.13.0 does not support subtraction between booleans
+ # TODO(niboshi): Write a separate test to check both NumPy and CuPy
+ # raise TypeError.
+ if (numpy_satisfies('>=1.13.0')
+ and self.name == 'subtract'
+ and xp.asarray(arg1).dtype == numpy.bool_
+ and xp.asarray(arg2).dtype == numpy.bool_):
+ return xp.array(True)
+
+
func = getattr(xp, self.name)
with testing.NumpyError(divide='ignore'):
with numpy.warnings.catch_warnings():
