5
5
6
6
import arrayfire_wrapper .dtypes as dtype
7
7
import arrayfire_wrapper .lib as wrapper
8
-
9
- from . import utility_functions as util
8
+ from tests .utility_functions import check_type_supported , get_all_types , get_real_types , get_complex_types
10
9
11
10
12
11
@pytest .mark .parametrize (
19
18
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
20
19
],
21
20
)
22
- @pytest .mark .parametrize ("dtype_name" , util . get_all_types ())
21
+ @pytest .mark .parametrize ("dtype_name" , get_all_types ())
23
22
def test_abs_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
24
23
"""Test absolute value operation between two arrays of the same shape"""
25
- util . check_type_supported (dtype_name )
24
+ check_type_supported (dtype_name )
26
25
out = wrapper .randu (shape , dtype_name )
27
26
28
27
result = wrapper .abs_ (out )
@@ -41,10 +40,10 @@ def test_abs_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
41
40
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
42
41
],
43
42
)
44
- @pytest .mark .parametrize ("dtype_name" , util . get_all_types ())
43
+ @pytest .mark .parametrize ("dtype_name" , get_all_types ())
45
44
def test_arg_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
46
45
"""Test arg operation between two arrays of the same shape"""
47
- util . check_type_supported (dtype_name )
46
+ check_type_supported (dtype_name )
48
47
out = wrapper .randu (shape , dtype_name )
49
48
50
49
result = wrapper .arg (out )
@@ -63,10 +62,10 @@ def test_arg_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
63
62
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
64
63
],
65
64
)
66
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
65
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
67
66
def test_ceil_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
68
67
"""Test ceil operation between two arrays of the same shape"""
69
- util . check_type_supported (dtype_name )
68
+ check_type_supported (dtype_name )
70
69
out = wrapper .randu (shape , dtype_name )
71
70
72
71
result = wrapper .ceil (out )
@@ -104,10 +103,10 @@ def test_ceil_shapes_invalid(invdtypes: dtype.Dtype) -> None:
104
103
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
105
104
],
106
105
)
107
- @pytest .mark .parametrize ("dtype_name" , util . get_all_types ())
106
+ @pytest .mark .parametrize ("dtype_name" , get_all_types ())
108
107
def test_maxof_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
109
108
"""Test maxof operation between two arrays of the same shape"""
110
- util . check_type_supported (dtype_name )
109
+ check_type_supported (dtype_name )
111
110
lhs = wrapper .randu (shape , dtype_name )
112
111
rhs = wrapper .randu (shape , dtype_name )
113
112
@@ -150,10 +149,10 @@ def test_maxof_varying_dimensionality(shape_a: tuple, shape_b: tuple) -> None:
150
149
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
151
150
],
152
151
)
153
- @pytest .mark .parametrize ("dtype_name" , util . get_all_types ())
152
+ @pytest .mark .parametrize ("dtype_name" , get_all_types ())
154
153
def test_minof_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
155
154
"""Test minof operation between two arrays of the same shape"""
156
- util . check_type_supported (dtype_name )
155
+ check_type_supported (dtype_name )
157
156
lhs = wrapper .randu (shape , dtype_name )
158
157
rhs = wrapper .randu (shape , dtype_name )
159
158
@@ -196,10 +195,10 @@ def test_minof_varying_dimensionality(shape_a: tuple, shape_b: tuple) -> None:
196
195
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
197
196
],
198
197
)
199
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
198
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
200
199
def test_mod_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
201
200
"""Test mod operation between two arrays of the same shape"""
202
- util . check_type_supported (dtype_name )
201
+ check_type_supported (dtype_name )
203
202
lhs = wrapper .randu (shape , dtype_name )
204
203
rhs = wrapper .randu (shape , dtype_name )
205
204
@@ -210,7 +209,7 @@ def test_mod_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
210
209
), f"failed for shape: { shape } and dtype { dtype_name } "
211
210
212
211
213
- @pytest .mark .parametrize ("invdtypes" , util . get_complex_types ())
212
+ @pytest .mark .parametrize ("invdtypes" , get_complex_types ())
214
213
def test_mod_shapes_invalid (invdtypes : dtype .Dtype ) -> None :
215
214
"""Test mod operation between two arrays of the same shape"""
216
215
with pytest .raises (RuntimeError ):
@@ -235,10 +234,10 @@ def test_mod_shapes_invalid(invdtypes: dtype.Dtype) -> None:
235
234
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
236
235
],
237
236
)
238
- @pytest .mark .parametrize ("dtype_name" , util . get_all_types ())
237
+ @pytest .mark .parametrize ("dtype_name" , get_all_types ())
239
238
def test_neg_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
240
239
"""Test arg operation between two arrays of the same shape"""
241
- util . check_type_supported (dtype_name )
240
+ check_type_supported (dtype_name )
242
241
out = wrapper .randu (shape , dtype_name )
243
242
244
243
result = wrapper .neg (out )
@@ -257,10 +256,10 @@ def test_neg_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
257
256
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
258
257
],
259
258
)
260
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
259
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
261
260
def test_rem_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
262
261
"""Test remainder operation between two arrays of the same shape"""
263
- util . check_type_supported (dtype_name )
262
+ check_type_supported (dtype_name )
264
263
lhs = wrapper .randu (shape , dtype_name )
265
264
rhs = wrapper .randu (shape , dtype_name )
266
265
@@ -281,10 +280,10 @@ def test_rem_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
281
280
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
282
281
],
283
282
)
284
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
283
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
285
284
def test_round_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
286
285
"""Test round operation between two arrays of the same shape"""
287
- util . check_type_supported (dtype_name )
286
+ check_type_supported (dtype_name )
288
287
out = wrapper .randu (shape , dtype_name )
289
288
290
289
result = wrapper .round_ (out )
@@ -293,7 +292,7 @@ def test_round_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
293
292
), f"failed for shape: { shape } and dtype { dtype_name } "
294
293
295
294
296
- @pytest .mark .parametrize ("invdtypes" , util . get_complex_types ())
295
+ @pytest .mark .parametrize ("invdtypes" , get_complex_types ())
297
296
def test_round_shapes_invalid (invdtypes : dtype .Dtype ) -> None :
298
297
"""Test round operation between two arrays of the same shape"""
299
298
with pytest .raises (RuntimeError ):
@@ -316,10 +315,10 @@ def test_round_shapes_invalid(invdtypes: dtype.Dtype) -> None:
316
315
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
317
316
],
318
317
)
319
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
318
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
320
319
def test_sign_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
321
320
"""Test round operation between two arrays of the same shape"""
322
- util . check_type_supported (dtype_name )
321
+ check_type_supported (dtype_name )
323
322
out = wrapper .randu (shape , dtype_name )
324
323
325
324
result = wrapper .sign (out )
@@ -328,7 +327,7 @@ def test_sign_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
328
327
), f"failed for shape: { shape } and dtype { dtype_name } "
329
328
330
329
331
- @pytest .mark .parametrize ("invdtypes" , util . get_complex_types ())
330
+ @pytest .mark .parametrize ("invdtypes" , get_complex_types ())
332
331
def test_sign_shapes_invalid (invdtypes : dtype .Dtype ) -> None :
333
332
"""Test sign operation between two arrays of the same shape"""
334
333
with pytest .raises (RuntimeError ):
@@ -351,10 +350,10 @@ def test_sign_shapes_invalid(invdtypes: dtype.Dtype) -> None:
351
350
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
352
351
],
353
352
)
354
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
353
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
355
354
def test_trunc_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
356
355
"""Test truncating operation for an array with varying shape"""
357
- util . check_type_supported (dtype_name )
356
+ check_type_supported (dtype_name )
358
357
out = wrapper .randu (shape , dtype_name )
359
358
360
359
result = wrapper .trunc (out )
@@ -363,7 +362,7 @@ def test_trunc_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
363
362
), f"failed for shape: { shape } and dtype { dtype_name } "
364
363
365
364
366
- @pytest .mark .parametrize ("invdtypes" , util . get_complex_types ())
365
+ @pytest .mark .parametrize ("invdtypes" , get_complex_types ())
367
366
def test_trunc_shapes_invalid (invdtypes : dtype .Dtype ) -> None :
368
367
"""Test trunc operation for an array with varrying shape and invalid dtypes"""
369
368
with pytest .raises (RuntimeError ):
@@ -424,14 +423,13 @@ def test_hypot_unsupported_dtypes(invdtypes: dtype.Dtype) -> None:
424
423
(random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
425
424
],
426
425
)
427
- @pytest .mark .parametrize ("dtype_name" , util . get_real_types ())
426
+ @pytest .mark .parametrize ("dtype_name" , get_real_types ())
428
427
def test_clamp_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
429
428
"""Test clamp operation between two arrays of the same shape"""
430
- util . check_type_supported (dtype_name )
429
+ check_type_supported (dtype_name )
431
430
og = wrapper .randu (shape , dtype_name )
432
431
low = wrapper .randu (shape , dtype_name )
433
432
high = wrapper .randu (shape , dtype_name )
434
- # talked to stefan about this, testing broadcasting is unnecessary
435
433
result = wrapper .clamp (og , low , high , False )
436
434
assert (
437
435
wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
0 commit comments