4
4
import pytest
5
5
6
6
import dpnp as cupy
7
+ from dpnp .tests .helper import has_support_aspect64
7
8
from dpnp .tests .third_party .cupy import testing
8
9
9
10
10
11
class TestElementwise (unittest .TestCase ):
12
+
11
13
def check_copy (self , dtype , src_id , dst_id ):
12
14
with cuda .Device (src_id ):
13
15
src = testing .shaped_arange ((2 , 3 , 4 ), dtype = dtype )
@@ -16,21 +18,21 @@ def check_copy(self, dtype, src_id, dst_id):
16
18
_core .elementwise_copy (src , dst )
17
19
testing .assert_allclose (src , dst )
18
20
19
- @pytest .mark .skip ("`device` argument isn't supported" )
21
+ @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
20
22
@testing .for_all_dtypes ()
21
23
def test_copy (self , dtype ):
22
24
device_id = cuda .Device ().id
23
25
self .check_copy (dtype , device_id , device_id )
24
26
25
- @pytest .mark .skip ("`device` argument isn't supported" )
27
+ @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
26
28
@testing .for_all_dtypes ()
27
29
def test_copy_multigpu_nopeer (self , dtype ):
28
30
if cuda .runtime .deviceCanAccessPeer (0 , 1 ) == 1 :
29
31
pytest .skip ("peer access is available" )
30
32
with self .assertRaises (ValueError ):
31
33
self .check_copy (dtype , 0 , 1 )
32
34
33
- @pytest .mark .skip ("`device` argument isn't supported" )
35
+ @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
34
36
@testing .for_all_dtypes ()
35
37
def test_copy_multigpu_peer (self , dtype ):
36
38
if cuda .runtime .deviceCanAccessPeer (0 , 1 ) != 1 :
@@ -67,8 +69,9 @@ def test_copy_orders(self, order):
67
69
assert b .strides == tuple (x / b_cpu .itemsize for x in b_cpu .strides )
68
70
69
71
70
- @pytest .mark .skip ("`ElementwiseKernel` function isn't supported" )
72
+ @pytest .mark .skip ("`ElementwiseKernel` isn't supported" )
71
73
class TestElementwiseInvalidShape (unittest .TestCase ):
74
+
72
75
def test_invalid_shape (self ):
73
76
with self .assertRaisesRegex (ValueError , "Out shape is mismatched" ):
74
77
f = cupy .ElementwiseKernel ("T x" , "T y" , "y += x" )
@@ -77,67 +80,102 @@ def test_invalid_shape(self):
77
80
f (x , y )
78
81
79
82
80
- @pytest .mark .skip ("`ElementwiseKernel` function isn't supported" )
83
+ @pytest .mark .skip ("`ElementwiseKernel` isn't supported" )
81
84
class TestElementwiseInvalidArgument (unittest .TestCase ):
85
+
82
86
def test_invalid_kernel_name (self ):
83
87
with self .assertRaisesRegex (ValueError , "Invalid kernel name" ):
84
88
cupy .ElementwiseKernel ("T x" , "" , "" , "1" )
85
89
86
90
87
- @pytest .mark .skip ("`iinfo` function isn't supported" )
88
91
class TestElementwiseType (unittest .TestCase ):
92
+
93
+ @testing .with_requires ("numpy>=2.0" )
89
94
@testing .for_int_dtypes (no_bool = True )
90
- @testing .numpy_cupy_array_equal ()
95
+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
91
96
def test_large_int_upper_1 (self , xp , dtype ):
92
- a = xp .array ([0 ], dtype = xp .int8 )
97
+ a = xp .array ([0 ], dtype = numpy .int8 )
93
98
b = xp .iinfo (dtype ).max
94
99
return a + b
95
100
96
101
@testing .for_int_dtypes (no_bool = True )
97
- @testing .numpy_cupy_array_equal ()
102
+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
98
103
def test_large_int_upper_2 (self , xp , dtype ):
99
- a = xp .array ([1 ], dtype = xp .int8 )
104
+ if (
105
+ numpy .issubdtype (dtype , numpy .unsignedinteger )
106
+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
107
+ ):
108
+ pytest .skip ("numpy promotes dtype differently" )
109
+
110
+ a = xp .array ([1 ], dtype = numpy .int8 )
100
111
b = xp .iinfo (dtype ).max - 1
101
112
return a + b
102
113
103
114
@testing .for_int_dtypes (no_bool = True )
104
115
@testing .numpy_cupy_array_equal ()
105
116
def test_large_int_upper_3 (self , xp , dtype ):
117
+ if (
118
+ numpy .issubdtype (dtype , numpy .unsignedinteger )
119
+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
120
+ ):
121
+ pytest .skip ("numpy promotes dtype differently" )
122
+ elif dtype == numpy .uint64 and not has_support_aspect64 ():
123
+ pytest .skip ("no fp64 support" )
124
+
106
125
a = xp .array ([xp .iinfo (dtype ).max ], dtype = dtype )
107
- b = xp .int8 (0 )
126
+ b = numpy .int8 (0 )
108
127
return a + b
109
128
110
129
@testing .for_int_dtypes (no_bool = True )
111
130
@testing .numpy_cupy_array_equal ()
112
131
def test_large_int_upper_4 (self , xp , dtype ):
132
+ if (
133
+ numpy .issubdtype (dtype , numpy .unsignedinteger )
134
+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
135
+ ):
136
+ pytest .skip ("numpy promotes dtype differently" )
137
+ elif dtype == numpy .uint64 and not has_support_aspect64 ():
138
+ pytest .skip ("no fp64 support" )
139
+
113
140
a = xp .array ([xp .iinfo (dtype ).max - 1 ], dtype = dtype )
114
- b = xp .int8 (1 )
141
+ b = numpy .int8 (1 )
115
142
return a + b
116
143
117
144
@testing .for_int_dtypes (no_bool = True )
118
- @testing .numpy_cupy_array_equal ()
145
+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
119
146
def test_large_int_lower_1 (self , xp , dtype ):
120
- a = xp .array ([0 ], dtype = xp .int8 )
147
+ a = xp .array ([0 ], dtype = numpy .int8 )
121
148
b = xp .iinfo (dtype ).min
122
149
return a + b
123
150
124
151
@testing .for_int_dtypes (no_bool = True )
125
- @testing .numpy_cupy_array_equal ()
152
+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
126
153
def test_large_int_lower_2 (self , xp , dtype ):
127
- a = xp .array ([- 1 ], dtype = xp .int8 )
154
+ a = xp .array ([- 1 ], dtype = numpy .int8 )
128
155
b = xp .iinfo (dtype ).min + 1
129
156
return a + b
130
157
131
158
@testing .for_int_dtypes (no_bool = True )
132
159
@testing .numpy_cupy_array_equal ()
133
160
def test_large_int_lower_3 (self , xp , dtype ):
161
+ if (
162
+ numpy .issubdtype (dtype , numpy .unsignedinteger )
163
+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
164
+ ):
165
+ pytest .skip ("numpy promotes dtype differently" )
166
+ elif dtype == numpy .uint64 and not has_support_aspect64 ():
167
+ pytest .skip ("no fp64 support" )
168
+
134
169
a = xp .array ([xp .iinfo (dtype ).min ], dtype = dtype )
135
- b = xp .int8 (0 )
170
+ b = numpy .int8 (0 )
136
171
return a + b
137
172
138
173
@testing .for_int_dtypes (no_bool = True )
139
174
@testing .numpy_cupy_array_equal ()
140
175
def test_large_int_lower_4 (self , xp , dtype ):
176
+ if dtype == numpy .uint64 and not has_support_aspect64 ():
177
+ pytest .skip ("no fp64 support" )
178
+
141
179
a = xp .array ([xp .iinfo (dtype ).min + 1 ], dtype = dtype )
142
- b = xp .int8 (- 1 )
180
+ b = numpy .int8 (- 1 )
143
181
return a + b
0 commit comments