generate arrays using xp
@@ -6,7 +6,7 @@ import cupy
from cupy import testing
-def _generate_type_routines_input(dtype, obj_type):
+def _generate_type_routines_input(xp, dtype, obj_type):
dtype = numpy.dtype(dtype)
if obj_type == 'dtype':
return dtype
@@ -15,7 +15,7 @@ def _generate_type_routines_input(dtype, obj_type):
if obj_type == 'scalar':
return dtype.type(3)
if obj_type == 'array':
- return cupy.zeros(3, dtype=dtype)
+ return xp.zeros(3, dtype=dtype)
if obj_type == 'primitive':
return type(dtype.type(3).tolist())
assert False
@@ -31,7 +31,7 @@ class TestCanCast(unittest.TestCase):
@testing.for_all_dtypes_combination(names=('from_dtype', 'to_dtype'))
@testing.numpy_cupy_equal()
def test_can_cast(self, xp, from_dtype, to_dtype):
- from_obj = _generate_type_routines_input(from_dtype, self.obj_type)
+ from_obj = _generate_type_routines_input(xp, from_dtype, self.obj_type)
return xp.can_cast(from_obj, to_dtype)
@@ -40,8 +40,8 @@ class TestCommonType(unittest.TestCase):
@testing.for_dtypes_combination('efdFD', names=('dtype1', 'dtype2'))
@testing.numpy_cupy_equal()
def test_common_type(self, xp, dtype1, dtype2):
- array1 = _generate_type_routines_input(dtype1, 'array')
- array2 = _generate_type_routines_input(dtype2, 'array')
+ array1 = _generate_type_routines_input(xp, dtype1, 'array')
+ array2 = _generate_type_routines_input(xp, dtype2, 'array')
return xp.common_type(array1, array2)
@@ -56,6 +56,6 @@ class TestResultType(unittest.TestCase):
@testing.for_all_dtypes_combination(names=('dtype1', 'dtype2'))
@testing.numpy_cupy_equal()
def test_result_type(self, xp, dtype1, dtype2):
- input1 = _generate_type_routines_input(dtype1, self.obj_type1)
- input2 = _generate_type_routines_input(dtype2, self.obj_type2)
+ input1 = _generate_type_routines_input(xp, dtype1, self.obj_type1)
+ input2 = _generate_type_routines_input(xp, dtype2, self.obj_type2)
return xp.result_type(input1, input2)
