1313
1414from .helper import (
1515 assert_dtype_allclose ,
16+ generate_random_numpy_array ,
1617 get_abs_array ,
1718 get_all_dtypes ,
1819 get_complex_dtypes ,
2223 has_support_aspect16 ,
2324 numpy_version ,
2425)
25- from .test_umath import (
26- _get_numpy_arrays_2in_1out ,
27- _get_output_data_type ,
28- )
2926
3027"""
3128The scope includes tests with only functions which are instances of
@@ -39,7 +36,9 @@ class TestAdd:
3936
4037 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
4138 def test_add (self , dtype ):
42- a , b , expected = _get_numpy_arrays_2in_1out ("add" , dtype , [- 5 , 5 , 10 ])
39+ a = generate_random_numpy_array (10 , dtype )
40+ b = generate_random_numpy_array (10 , dtype )
41+ expected = numpy .add (a , b )
4342
4443 ia , ib = dpnp .array (a ), dpnp .array (b )
4544 iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -139,91 +138,63 @@ def test_invalid_out(self, xp, out):
139138 assert_raises (TypeError , xp .add , a , 2 , out )
140139
141140
141+ @pytest .mark .parametrize ("func" , ["fmax" , "fmin" , "maximum" , "minimum" ])
142142class TestBoundFuncs :
143- @pytest .fixture (
144- params = [
145- {"func_name" : "fmax" , "input_values" : [- 5 , 5 , 10 ]},
146- {"func_name" : "fmin" , "input_values" : [- 5 , 5 , 10 ]},
147- {"func_name" : "maximum" , "input_values" : [- 5 , 5 , 10 ]},
148- {"func_name" : "minimum" , "input_values" : [- 5 , 5 , 10 ]},
149- ],
150- ids = [
151- "fmax" ,
152- "fmin" ,
153- "maximum" ,
154- "minimum" ,
155- ],
156- )
157- def func_params (self , request ):
158- return request .param
159-
160- @pytest .mark .parametrize (
161- "dtype" , get_all_dtypes (no_bool = True , no_complex = True )
162- )
163- def test_out (self , func_params , dtype ):
164- func_name = func_params ["func_name" ]
165- input_values = func_params ["input_values" ]
166- a , b , expected = _get_numpy_arrays_2in_1out (
167- func_name , dtype , input_values
168- )
143+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
144+ def test_out (self , func , dtype ):
145+ a = generate_random_numpy_array (10 , dtype )
146+ b = generate_random_numpy_array (10 , dtype )
147+ expected = getattr (numpy , func )(a , b )
169148
170149 ia , ib = dpnp .array (a ), dpnp .array (b )
171150 iout = dpnp .empty (expected .shape , dtype = dtype )
172- result = getattr (dpnp , func_name )(ia , ib , out = iout )
151+ result = getattr (dpnp , func )(ia , ib , out = iout )
173152
174153 assert result is iout
175154 assert_dtype_allclose (result , expected )
176155
177156 @pytest .mark .parametrize (
178- "dtype" , get_all_dtypes (no_bool = True , no_complex = True )
157+ "dtype" , get_all_dtypes (no_none = True , no_bool = True )
179158 )
180- def test_out_overlap (self , func_params , dtype ):
181- func_name = func_params ["func_name" ]
159+ def test_out_overlap (self , func , dtype ):
182160 size = 15
183161 a = numpy .arange (2 * size , dtype = dtype )
184162 ia = dpnp .array (a )
185163
186- getattr (dpnp , func_name )(ia [size ::], ia [::2 ], out = ia [:size :])
187- getattr (numpy , func_name )(a [size ::], a [::2 ], out = a [:size :])
164+ getattr (dpnp , func )(ia [size ::], ia [::2 ], out = ia [:size :])
165+ getattr (numpy , func )(a [size ::], a [::2 ], out = a [:size :])
188166
189167 assert_dtype_allclose (ia , a )
190168
191169 @pytest .mark .parametrize ("shape" , [(0 ,), (15 ,), (2 , 2 )])
192- def test_invalid_shape (self , func_params , shape ):
193- func_name = func_params ["func_name" ]
170+ def test_invalid_shape (self , func , shape ):
194171 a , b = dpnp .arange (10 ), dpnp .arange (10 )
195172 out = dpnp .empty (shape )
196173
197174 with pytest .raises (ValueError ):
198- getattr (dpnp , func_name )(a , b , out = out )
175+ getattr (dpnp , func )(a , b , out = out )
199176
200177 @pytest .mark .parametrize ("xp" , [dpnp , numpy ])
201178 @pytest .mark .parametrize (
202179 "out" ,
203180 [4 , (), [], (3 , 7 ), [2 , 4 ]],
204181 ids = ["scalar" , "empty_tuple" , "empty_list" , "tuple" , "list" ],
205182 )
206- def test_invalid_out (self , func_params , xp , out ):
207- func_name = func_params ["func_name" ]
183+ def test_invalid_out (self , func , xp , out ):
208184 a = xp .arange (10 )
209- assert_raises (TypeError , getattr (xp , func_name ), a , 2 , out )
185+ assert_raises (TypeError , getattr (xp , func ), a , 2 , out )
210186
211187
212188class TestDivide :
213189 @pytest .mark .usefixtures ("suppress_divide_invalid_numpy_warnings" )
214- @pytest .mark .parametrize (
215- "dtype" , get_all_dtypes (no_none = True , no_bool = True )
216- )
190+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
217191 def test_divide (self , dtype ):
218- a , b , expected = _get_numpy_arrays_2in_1out (
219- "divide" , dtype , [ - 5 , 5 , 10 ]
220- )
192+ a = generate_random_numpy_array ( 10 , dtype )
193+ b = generate_random_numpy_array ( 10 , dtype )
194+ expected = numpy . divide ( a , b )
221195
222196 ia , ib = dpnp .array (a ), dpnp .array (b )
223- if numpy .issubdtype (dtype , numpy .integer ):
224- out_dtype = map_dtype_to_device (dpnp .float64 , ia .sycl_device )
225- else :
226- out_dtype = _get_output_data_type (dtype )
197+ out_dtype = map_dtype_to_device (expected .dtype , ia .sycl_device )
227198 iout = dpnp .empty (expected .shape , dtype = out_dtype )
228199 result = dpnp .divide (ia , ib , out = iout )
229200
@@ -318,7 +289,9 @@ def do_inplace_op(self, base, other, func):
318289 @pytest .mark .usefixtures ("suppress_divide_numpy_warnings" )
319290 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
320291 def test_basic (self , func , dtype ):
321- a , b , expected = _get_numpy_arrays_2in_1out (func , dtype , [- 5 , 5 , 10 ])
292+ a = generate_random_numpy_array (10 , dtype )
293+ b = generate_random_numpy_array (10 , dtype )
294+ expected = getattr (numpy , func )(a , b )
322295
323296 ia , ib = dpnp .array (a ), dpnp .array (b )
324297 iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -398,9 +371,9 @@ def test_invalid_out(self, func, xp, out):
398371 assert_raises (TypeError , getattr (xp , func ), a , 2 , out )
399372
400373
374+ @pytest .mark .parametrize ("func" , ["fmax" , "fmin" ])
401375class TestFmaxFmin :
402376 @pytest .mark .skipif (not has_support_aspect16 (), reason = "no fp16 support" )
403- @pytest .mark .parametrize ("func" , ["fmax" , "fmin" ])
404377 def test_half (self , func ):
405378 a = numpy .array ([0 , 1 , 2 , 4 , 2 ], dtype = numpy .float16 )
406379 b = numpy .array ([- 2 , 5 , 1 , 4 , 3 ], dtype = numpy .float16 )
@@ -415,7 +388,6 @@ def test_half(self, func):
415388 expected = getattr (numpy , func )(b , c )
416389 assert_equal (result , expected )
417390
418- @pytest .mark .parametrize ("func" , ["fmax" , "fmin" ])
419391 @pytest .mark .parametrize ("dtype" , get_float_dtypes ())
420392 def test_float_nans (self , func , dtype ):
421393 a = numpy .array ([0 , numpy .nan , numpy .nan ], dtype = dtype )
@@ -426,7 +398,6 @@ def test_float_nans(self, func, dtype):
426398 expected = getattr (numpy , func )(a , b )
427399 assert_equal (result , expected )
428400
429- @pytest .mark .parametrize ("func" , ["fmax" , "fmin" ])
430401 @pytest .mark .parametrize ("dtype" , get_complex_dtypes ())
431402 @pytest .mark .parametrize (
432403 "nan_val" ,
@@ -446,7 +417,6 @@ def test_complex_nans(self, func, dtype, nan_val):
446417 expected = getattr (numpy , func )(a , b )
447418 assert_equal (result , expected )
448419
449- @pytest .mark .parametrize ("func" , ["fmax" , "fmin" ])
450420 @pytest .mark .parametrize ("dtype" , get_float_dtypes (no_float16 = False ))
451421 def test_precision (self , func , dtype ):
452422 dtmin = numpy .finfo (dtype ).min
@@ -602,9 +572,9 @@ class TestMultiply:
602572
603573 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
604574 def test_multiply (self , dtype ):
605- a , b , expected = _get_numpy_arrays_2in_1out (
606- "multiply" , dtype , [ 0 , 10 , 10 ]
607- )
575+ a = generate_random_numpy_array ( 10 , dtype )
576+ b = generate_random_numpy_array ( 10 , dtype )
577+ expected = numpy . multiply ( a , b )
608578
609579 ia , ib = dpnp .array (a ), dpnp .array (b )
610580 iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -853,8 +823,9 @@ def test_basic(self, array, val, data_type, val_type):
853823
854824 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
855825 def test_power (self , dtype ):
856- numpy .random .seed (42 )
857- a , b , expected = _get_numpy_arrays_2in_1out ("power" , dtype , [0 , 10 , 10 ])
826+ a = generate_random_numpy_array (10 , dtype , low = 0 )
827+ b = generate_random_numpy_array (10 , dtype , low = 0 )
828+ expected = numpy .power (a , b )
858829
859830 ia , ib = dpnp .array (a ), dpnp .array (b )
860831 out_dtype = numpy .int8 if dtype == numpy .bool_ else dtype
@@ -1075,9 +1046,9 @@ class TestSubtract:
10751046
10761047 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
10771048 def test_add (self , dtype ):
1078- a , b , expected = _get_numpy_arrays_2in_1out (
1079- "subtract" , dtype , [ - 5 , 5 , 10 ]
1080- )
1049+ a = generate_random_numpy_array ( 10 , dtype )
1050+ b = generate_random_numpy_array ( 10 , dtype )
1051+ expected = numpy . subtract ( a , b )
10811052
10821053 ia , ib = dpnp .array (a ), dpnp .array (b )
10831054 iout = dpnp .empty (expected .shape , dtype = dtype )
0 commit comments