@@ -34,11 +34,13 @@ class TestCanCast(unittest.TestCase):
34
34
@testing .for_all_dtypes_combination (names = ("from_dtype" , "to_dtype" ))
35
35
@testing .numpy_cupy_equal ()
36
36
def test_can_cast (self , xp , from_dtype , to_dtype ):
37
- if self .obj_type == "scalar" :
37
+ if (
38
+ self .obj_type == "scalar"
39
+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
40
+ ):
38
41
pytest .skip ("to be aligned with NEP-50" )
39
42
40
43
from_obj = _generate_type_routines_input (xp , from_dtype , self .obj_type )
41
-
42
44
ret = xp .can_cast (from_obj , to_dtype )
43
45
assert isinstance (ret , bool )
44
46
return ret
@@ -92,37 +94,41 @@ class TestResultType(unittest.TestCase):
92
94
@testing .for_all_dtypes_combination (names = ("dtype1" , "dtype2" ))
93
95
@testing .numpy_cupy_equal ()
94
96
def test_result_type (self , xp , dtype1 , dtype2 ):
95
- if "scalar" in {self .obj_type1 , self .obj_type2 }:
97
+ if (
98
+ "scalar" in {self .obj_type1 , self .obj_type2 }
99
+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
100
+ ):
96
101
pytest .skip ("to be aligned with NEP-50" )
97
102
98
103
input1 = _generate_type_routines_input (xp , dtype1 , self .obj_type1 )
99
-
100
104
input2 = _generate_type_routines_input (xp , dtype2 , self .obj_type2 )
101
105
102
- flag1 = isinstance ( input1 , ( numpy . ndarray , cupy . ndarray ))
103
- flag2 = isinstance ( input2 , ( numpy . ndarray , cupy . ndarray ))
104
- dt1 = cupy . dtype ( input1 ) if not flag1 else None
105
- dt2 = cupy . dtype ( input2 ) if not flag2 else None
106
- # dpnp takes into account device capabilities only if one of the
107
- # inputs is an array, for such a case, if the other dtype is not
108
- # supported by device, dpnp raise ValueError. So, we skip the test .
109
- if flag1 or flag2 :
110
- if (
111
- dt1 in [ cupy . float64 , cupy . complex128 ]
112
- or dt2 in [ cupy . float64 , cupy . complex128 ]
113
- ) and not has_support_aspect64 ():
114
- pytest .skip ("No fp64 support by device." )
106
+ flag1 = self . obj_type1 == "array" or self . obj_type2 == "array"
107
+ flag2 = ( self . obj_type1 == "primitive" and input1 == float ) or (
108
+ self . obj_type2 == "primitive" and input2 == float
109
+ )
110
+ # dpnp.result_type only takes into account device capabilities if
111
+ # at least one of the inputs is an array, for such a case, if the other
112
+ # input not supported by device, dpnp raises ValueError.
113
+ # If input dtype is `float32` and the object is primitive, the final
114
+ # dtype is `float` which needs a device with double precision support.
115
+ # so we skip the test in such case, i.e. for a case when one input is
116
+ # array and the other is a primitive obj with dtype 'float`.
117
+ if flag1 and flag2 and not has_support_aspect64 ():
118
+ pytest .skip ("No fp64 support by device." )
115
119
116
120
ret = xp .result_type (input1 , input2 )
117
121
118
- # dpnp takes into account device capabilities if one of the inputs
119
- # is an array, for such a case, we have to modify the results for
120
- # NumPy to align it with device capabilities.
121
- if (flag1 or flag2 ) and xp == numpy and not has_support_aspect64 ():
122
- ret = numpy .dtype (numpy .float32 ) if ret == numpy .float64 else ret
123
- ret = (
124
- numpy .dtype (numpy .complex64 ) if ret == numpy .complex128 else ret
125
- )
122
+ # dpnp.result_type only takes into account device capabilities if at least one
123
+ # of the inputs is an array, for such a case, we have to modify the
124
+ # results for NumPy to align it with device capabilities.
125
+ flag1 = isinstance (input1 , numpy .ndarray )
126
+ flag2 = isinstance (input2 , numpy .ndarray )
127
+ if (flag1 or flag2 ) and not has_support_aspect64 ():
128
+ if ret == numpy .float64 :
129
+ ret = numpy .dtype (numpy .float32 )
130
+ elif ret == numpy .complex128 :
131
+ ret = numpy .dtype (numpy .complex64 )
126
132
127
133
assert isinstance (ret , numpy .dtype )
128
134
return ret
0 commit comments