1- import unittest
2-
31import numpy
2+ import pytest
43
54from dpnp .tests .third_party .cupy import testing
65
@@ -39,7 +38,8 @@ def _calc_out_shape(shape, axis, keepdims):
3938 }
4039 )
4140)
42- class TestAllAny (unittest .TestCase ):
41+ class TestAllAny :
42+
4343 @testing .for_all_dtypes ()
4444 @testing .numpy_cupy_array_equal ()
4545 def test_without_out (self , xp , dtype ):
@@ -71,7 +71,8 @@ def test_with_out(self, xp, dtype):
7171 }
7272 )
7373)
74- class TestAllAnyWithNaN (unittest .TestCase ):
74+ class TestAllAnyWithNaN :
75+
7576 @testing .for_dtypes ((* testing ._loops ._float_dtypes , numpy .bool_ ))
7677 @testing .numpy_cupy_array_equal ()
7778 def test_without_out (self , xp , dtype ):
@@ -86,3 +87,205 @@ def test_with_out(self, xp, dtype):
8687 out = xp .empty (out_shape , dtype = x .dtype )
8788 getattr (xp , self .f )(x , self .axis , out , self .keepdims )
8889 return out
90+
91+
92+ @pytest .mark .skip ("isin() is not supported yet" )
93+ @testing .parameterize (
94+ * testing .product (
95+ {
96+ "shape_x" : [(0 ,), (3 ,), (2 , 3 ), (2 , 1 , 3 ), (2 , 0 , 1 ), (2 , 0 , 1 , 1 )],
97+ "shape_y" : [(0 ,), (3 ,), (2 , 3 ), (2 , 1 , 3 ), (2 , 0 , 1 ), (2 , 0 , 1 , 1 )],
98+ "assume_unique" : [False , True ],
99+ "invert" : [False , True ],
100+ }
101+ )
102+ )
103+ class TestIn1DIsIn :
104+
105+ @testing .for_all_dtypes ()
106+ @testing .numpy_cupy_array_equal ()
107+ def test (self , xp , dtype ):
108+ x = testing .shaped_arange (self .shape_x , xp , dtype )
109+ y = testing .shaped_arange (self .shape_y , xp , dtype )
110+ return xp .isin (x , y , self .assume_unique , self .invert )
111+
112+
113+ @pytest .mark .skip ("setdiff1d() is not supported yet" )
114+ class TestSetdiff1d :
115+
116+ @testing .for_all_dtypes ()
117+ @testing .numpy_cupy_array_equal ()
118+ def test_setdiff1d_same_arrays (self , xp , dtype ):
119+ x = xp .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
120+ y = xp .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
121+ return xp .setdiff1d (x , y , assume_unique = True )
122+
123+ @testing .for_all_dtypes ()
124+ @testing .numpy_cupy_array_equal ()
125+ def test_setdiff1d_diff_size_arr_inputs (self , xp , dtype ):
126+ x = xp .array ([3 , 4 , 9 , 1 , 5 , 4 ], dtype = dtype )
127+ y = xp .array ([8 , 7 , 3 , 9 , 0 ], dtype = dtype )
128+ return xp .setdiff1d (x , y )
129+
130+ @testing .for_all_dtypes ()
131+ @testing .numpy_cupy_array_equal ()
132+ def test_setdiff1d_diff_elements (self , xp , dtype ):
133+ x = xp .array ([3 , 4 , 9 , 1 , 5 , 4 ], dtype = dtype )
134+ y = xp .array ([8 , 7 , 3 , 9 , 0 ], dtype = dtype )
135+ return xp .setdiff1d (x , y , assume_unique = True )
136+
137+ @testing .for_all_dtypes ()
138+ @testing .numpy_cupy_array_equal ()
139+ def test_setdiff1d_with_2d (self , xp , dtype ):
140+ x = testing .shaped_random ((2 , 3 ), xp , dtype = dtype )
141+ y = testing .shaped_random ((3 , 5 ), xp , dtype = dtype )
142+ return xp .setdiff1d (x , y , assume_unique = True )
143+
144+ @testing .for_all_dtypes ()
145+ @testing .numpy_cupy_array_equal ()
146+ def test_setdiff1d_with_duplicate_elements (self , xp , dtype ):
147+ x = xp .array ([1 , 2 , 3 , 2 , 2 , 6 ], dtype = dtype )
148+ y = xp .array ([3 , 4 , 2 , 1 , 1 , 9 ], dtype = dtype )
149+ return xp .setdiff1d (x , y )
150+
151+ @testing .for_all_dtypes ()
152+ @testing .numpy_cupy_array_equal ()
153+ def test_setdiff1d_empty_arr (self , xp , dtype ):
154+ x = xp .array ([], dtype = dtype )
155+ y = xp .array ([], dtype = dtype )
156+ return xp .setdiff1d (x , y )
157+
158+ @testing .for_all_dtypes ()
159+ @testing .numpy_cupy_array_equal ()
160+ def test_setdiff1d_more_dim (self , xp , dtype ):
161+ x = testing .shaped_arange ((2 , 3 , 4 , 8 ), xp , dtype = dtype )
162+ y = testing .shaped_arange ((5 , 4 , 2 ), xp , dtype = dtype )
163+ return xp .setdiff1d (x , y , assume_unique = True )
164+
165+ @testing .numpy_cupy_array_equal ()
166+ def test_setdiff1d_bool_val (self , xp ):
167+ x = xp .array ([True , False , True ])
168+ y = xp .array ([False ])
169+ return xp .setdiff1d (x , y )
170+
171+
172+ @pytest .mark .skip ("setxor1d() is not supported yet" )
173+ class TestSetxor1d :
174+
175+ @testing .for_all_dtypes ()
176+ @testing .numpy_cupy_array_equal ()
177+ def test_setxor1d_same_arrays (self , xp , dtype ):
178+ x = xp .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
179+ y = xp .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
180+ return xp .setxor1d (x , y , assume_unique = True )
181+
182+ @testing .for_all_dtypes ()
183+ @testing .numpy_cupy_array_equal ()
184+ def test_setxor1d_diff_size_arr_inputs (self , xp , dtype ):
185+ x = xp .array ([3 , 4 , 9 , 1 , 5 , 4 ], dtype = dtype )
186+ y = xp .array ([8 , 7 , 3 , 9 , 0 ], dtype = dtype )
187+ return xp .setxor1d (x , y )
188+
189+ @testing .for_all_dtypes ()
190+ @testing .numpy_cupy_array_equal ()
191+ def test_setxor1d_diff_elements (self , xp , dtype ):
192+ x = xp .array ([3 , 4 , 9 , 1 , 5 , 4 ], dtype = dtype )
193+ y = xp .array ([8 , 7 , 3 , 9 , 0 ], dtype = dtype )
194+ return xp .setxor1d (x , y , assume_unique = True )
195+
196+ @testing .for_all_dtypes ()
197+ @testing .numpy_cupy_array_equal ()
198+ def test_setxor1d_with_2d (self , xp , dtype ):
199+ x = testing .shaped_random ((2 , 3 ), xp , dtype = dtype )
200+ y = testing .shaped_random ((3 , 5 ), xp , dtype = dtype )
201+ return xp .setxor1d (x , y )
202+
203+ @testing .for_all_dtypes ()
204+ @testing .numpy_cupy_array_equal ()
205+ def test_setxor1d_with_duplicate_elements (self , xp , dtype ):
206+ x = xp .array ([1 , 2 , 3 , 2 , 2 , 6 ], dtype = dtype )
207+ y = xp .array ([3 , 4 , 2 , 1 , 1 , 9 ], dtype = dtype )
208+ return xp .setxor1d (x , y )
209+
210+ @testing .for_all_dtypes ()
211+ @testing .numpy_cupy_array_equal ()
212+ def test_setxor1d_empty_arr (self , xp , dtype ):
213+ x = xp .array ([], dtype = dtype )
214+ y = xp .array ([], dtype = dtype )
215+ return xp .setxor1d (x , y )
216+
217+ @testing .for_all_dtypes ()
218+ @testing .numpy_cupy_array_equal ()
219+ def test_setxor1d_more_dim (self , xp , dtype ):
220+ x = testing .shaped_arange ((2 , 3 , 4 , 8 ), xp , dtype = dtype )
221+ y = testing .shaped_arange ((5 , 4 , 2 ), xp , dtype = dtype )
222+ return xp .setxor1d (x , y )
223+
224+ @testing .numpy_cupy_array_equal ()
225+ def test_setxor1d_bool_val (self , xp ):
226+ x = xp .array ([True , False , True ])
227+ y = xp .array ([False ])
228+ return xp .setxor1d (x , y )
229+
230+
231+ @pytest .mark .skip ("intersect1d() is not supported yet" )
232+ class TestIntersect1d :
233+
234+ @testing .for_all_dtypes (no_bool = True )
235+ @testing .numpy_cupy_array_equal ()
236+ def test_one_dim_with_unique_values (self , xp , dtype ):
237+ a = xp .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
238+ b = xp .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
239+ return xp .intersect1d (a , b , assume_unique = True )
240+
241+ @testing .for_all_dtypes ()
242+ @testing .numpy_cupy_array_equal ()
243+ def test_with_random_val (self , xp , dtype ):
244+ a = xp .array ([3 , 4 , 9 , 1 , 5 , 4 ], dtype = dtype )
245+ b = xp .array ([8 , 7 , 3 , 9 , 0 ], dtype = dtype )
246+ return xp .intersect1d (a , b )
247+
248+ @testing .for_all_dtypes ()
249+ @testing .numpy_cupy_array_equal ()
250+ def test_more_dim (self , xp , dtype ):
251+ a = testing .shaped_random ((3 , 4 ), xp , dtype = dtype )
252+ b = testing .shaped_random ((5 , 2 ), xp , dtype = dtype )
253+ return xp .intersect1d (a , b )
254+
255+ @testing .for_all_dtypes ()
256+ @testing .numpy_cupy_array_equal ()
257+ def test_return_indices (self , xp , dtype ):
258+ a = xp .array ([2 , 3 , 4 , 1 , 9 , 4 ], dtype = dtype )
259+ b = xp .array ([7 , 5 , 1 , 2 , 9 , 3 ], dtype = dtype )
260+ return xp .intersect1d (a , b , return_indices = True )
261+
262+ @testing .for_all_dtypes ()
263+ @testing .numpy_cupy_array_equal ()
264+ def test_multiple_instances (self , xp , dtype ):
265+ a = xp .array ([2 , 4 , 5 , 2 , 1 , 5 ], dtype = dtype )
266+ b = xp .array ([4 , 6 , 2 , 5 , 7 , 6 ], dtype = dtype )
267+ return xp .intersect1d (a , b , return_indices = True )
268+
269+
270+ @pytest .mark .skip ("union1d() is not supported yet" )
271+ class TestUnion1d :
272+
273+ @testing .for_all_dtypes ()
274+ @testing .numpy_cupy_array_equal ()
275+ def test_union1d (self , xp , dtype ):
276+ x = xp .array ([4 , 1 , 1 , 1 , 9 , 9 , 9 ], dtype = dtype )
277+ y = xp .array ([4 , 0 , 5 , 2 , 0 , 0 , 5 ], dtype = dtype )
278+ return xp .union1d (x , y )
279+
280+ @testing .for_all_dtypes ()
281+ @testing .numpy_cupy_array_equal ()
282+ def test_union1d_2 (self , xp , dtype ):
283+ x = testing .shaped_arange ((5 , 2 ), xp , dtype = dtype )
284+ y = testing .shaped_arange ((2 , 3 , 4 ), xp , dtype = dtype )
285+ return xp .union1d (x , y )
286+
287+ @testing .numpy_cupy_array_equal ()
288+ def test_union1d_3 (self , xp ):
289+ x = xp .zeros ((2 , 2 ), dtype = xp .complex128 )
290+ y = xp .array ([[1 + 1j , 2 + 3j ], [4 + 1j , 0 + 7j ]])
291+ return xp .union1d (x , y )
0 commit comments