13
13
14
14
from .helper import (
15
15
assert_dtype_allclose ,
16
+ generate_random_numpy_array ,
16
17
get_abs_array ,
17
18
get_all_dtypes ,
18
19
get_complex_dtypes ,
22
23
has_support_aspect16 ,
23
24
numpy_version ,
24
25
)
25
- from .test_umath import (
26
- _get_numpy_arrays_2in_1out ,
27
- _get_output_data_type ,
28
- )
26
+ from .test_umath import _get_output_data_type
29
27
30
28
"""
31
29
The scope includes tests with only functions which are instances of
@@ -39,7 +37,9 @@ class TestAdd:
39
37
40
38
@pytest .mark .parametrize ("dtype" , ALL_DTYPES )
41
39
def test_add (self , dtype ):
42
- a , b , expected = _get_numpy_arrays_2in_1out ("add" , dtype , [- 5 , 5 , 10 ])
40
+ a = generate_random_numpy_array (10 , dtype )
41
+ b = generate_random_numpy_array (10 , dtype )
42
+ expected = numpy .add (a , b )
43
43
44
44
ia , ib = dpnp .array (a ), dpnp .array (b )
45
45
iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -139,74 +139,53 @@ def test_invalid_out(self, xp, out):
139
139
assert_raises (TypeError , xp .add , a , 2 , out )
140
140
141
141
142
+ @pytest .mark .parametrize ("func" , ["fmax" , "fmin" , "maximum" , "minimum" ])
142
143
class 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
144
@pytest .mark .parametrize (
161
145
"dtype" , get_all_dtypes (no_bool = True , no_complex = True )
162
146
)
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
- )
147
+ def test_out (self , func , dtype ):
148
+ a = generate_random_numpy_array (10 , dtype )
149
+ b = generate_random_numpy_array (10 , dtype )
150
+ expected = getattr (numpy , func )(a , b )
169
151
170
152
ia , ib = dpnp .array (a ), dpnp .array (b )
171
153
iout = dpnp .empty (expected .shape , dtype = dtype )
172
- result = getattr (dpnp , func_name )(ia , ib , out = iout )
154
+ result = getattr (dpnp , func )(ia , ib , out = iout )
173
155
174
156
assert result is iout
175
157
assert_dtype_allclose (result , expected )
176
158
177
159
@pytest .mark .parametrize (
178
160
"dtype" , get_all_dtypes (no_bool = True , no_complex = True )
179
161
)
180
- def test_out_overlap (self , func_params , dtype ):
181
- func_name = func_params ["func_name" ]
162
+ def test_out_overlap (self , func , dtype ):
182
163
size = 15
183
164
a = numpy .arange (2 * size , dtype = dtype )
184
165
ia = dpnp .array (a )
185
166
186
- getattr (dpnp , func_name )(ia [size ::], ia [::2 ], out = ia [:size :])
187
- getattr (numpy , func_name )(a [size ::], a [::2 ], out = a [:size :])
167
+ getattr (dpnp , func )(ia [size ::], ia [::2 ], out = ia [:size :])
168
+ getattr (numpy , func )(a [size ::], a [::2 ], out = a [:size :])
188
169
189
170
assert_dtype_allclose (ia , a )
190
171
191
172
@pytest .mark .parametrize ("shape" , [(0 ,), (15 ,), (2 , 2 )])
192
- def test_invalid_shape (self , func_params , shape ):
193
- func_name = func_params ["func_name" ]
173
+ def test_invalid_shape (self , func , shape ):
194
174
a , b = dpnp .arange (10 ), dpnp .arange (10 )
195
175
out = dpnp .empty (shape )
196
176
197
177
with pytest .raises (ValueError ):
198
- getattr (dpnp , func_name )(a , b , out = out )
178
+ getattr (dpnp , func )(a , b , out = out )
199
179
200
180
@pytest .mark .parametrize ("xp" , [dpnp , numpy ])
201
181
@pytest .mark .parametrize (
202
182
"out" ,
203
183
[4 , (), [], (3 , 7 ), [2 , 4 ]],
204
184
ids = ["scalar" , "empty_tuple" , "empty_list" , "tuple" , "list" ],
205
185
)
206
- def test_invalid_out (self , func_params , xp , out ):
207
- func_name = func_params ["func_name" ]
186
+ def test_invalid_out (self , func , xp , out ):
208
187
a = xp .arange (10 )
209
- assert_raises (TypeError , getattr (xp , func_name ), a , 2 , out )
188
+ assert_raises (TypeError , getattr (xp , func ), a , 2 , out )
210
189
211
190
212
191
class TestDivide :
@@ -215,9 +194,9 @@ class TestDivide:
215
194
"dtype" , get_all_dtypes (no_none = True , no_bool = True )
216
195
)
217
196
def test_divide (self , dtype ):
218
- a , b , expected = _get_numpy_arrays_2in_1out (
219
- "divide" , dtype , [ - 5 , 5 , 10 ]
220
- )
197
+ a = generate_random_numpy_array ( 10 , dtype )
198
+ b = generate_random_numpy_array ( 10 , dtype )
199
+ expected = numpy . divide ( a , b )
221
200
222
201
ia , ib = dpnp .array (a ), dpnp .array (b )
223
202
if numpy .issubdtype (dtype , numpy .integer ):
@@ -318,7 +297,9 @@ def do_inplace_op(self, base, other, func):
318
297
@pytest .mark .usefixtures ("suppress_divide_numpy_warnings" )
319
298
@pytest .mark .parametrize ("dtype" , ALL_DTYPES )
320
299
def test_basic (self , func , dtype ):
321
- a , b , expected = _get_numpy_arrays_2in_1out (func , dtype , [- 5 , 5 , 10 ])
300
+ a = generate_random_numpy_array (10 , dtype )
301
+ b = generate_random_numpy_array (10 , dtype )
302
+ expected = getattr (numpy , func )(a , b )
322
303
323
304
ia , ib = dpnp .array (a ), dpnp .array (b )
324
305
iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -602,9 +583,9 @@ class TestMultiply:
602
583
603
584
@pytest .mark .parametrize ("dtype" , ALL_DTYPES )
604
585
def test_multiply (self , dtype ):
605
- a , b , expected = _get_numpy_arrays_2in_1out (
606
- "multiply" , dtype , [ 0 , 10 , 10 ]
607
- )
586
+ a = generate_random_numpy_array ( 10 , dtype )
587
+ b = generate_random_numpy_array ( 10 , dtype )
588
+ expected = numpy . multiply ( a , b )
608
589
609
590
ia , ib = dpnp .array (a ), dpnp .array (b )
610
591
iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -853,8 +834,9 @@ def test_basic(self, array, val, data_type, val_type):
853
834
854
835
@pytest .mark .parametrize ("dtype" , ALL_DTYPES )
855
836
def test_power (self , dtype ):
856
- numpy .random .seed (42 )
857
- a , b , expected = _get_numpy_arrays_2in_1out ("power" , dtype , [0 , 10 , 10 ])
837
+ a = generate_random_numpy_array (10 , dtype , low = 0 )
838
+ b = generate_random_numpy_array (10 , dtype , low = 0 )
839
+ expected = numpy .power (a , b )
858
840
859
841
ia , ib = dpnp .array (a ), dpnp .array (b )
860
842
out_dtype = numpy .int8 if dtype == numpy .bool_ else dtype
@@ -1075,9 +1057,9 @@ class TestSubtract:
1075
1057
1076
1058
@pytest .mark .parametrize ("dtype" , ALL_DTYPES )
1077
1059
def test_add (self , dtype ):
1078
- a , b , expected = _get_numpy_arrays_2in_1out (
1079
- "subtract" , dtype , [ - 5 , 5 , 10 ]
1080
- )
1060
+ a = generate_random_numpy_array ( 10 , dtype )
1061
+ b = generate_random_numpy_array ( 10 , dtype )
1062
+ expected = numpy . subtract ( a , b )
1081
1063
1082
1064
ia , ib = dpnp .array (a ), dpnp .array (b )
1083
1065
iout = dpnp .empty (expected .shape , dtype = dtype )
0 commit comments