1
1
import random
2
2
3
- import numpy as np
4
3
import pytest
5
4
6
5
import arrayfire_wrapper .dtypes as dtype
7
6
import arrayfire_wrapper .lib as wrapper
8
7
9
- from arrayfire_wrapper .lib .create_and_modify_array .helper_functions import array_to_string
10
-
11
8
dtype_map = {
12
9
"int16" : dtype .s16 ,
13
10
"int32" : dtype .s32 ,
@@ -56,7 +53,10 @@ def test_and_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
56
53
57
54
result = wrapper .and_ (lhs , rhs )
58
55
59
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
56
+ assert (
57
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
58
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
59
+
60
60
61
61
@pytest .mark .parametrize (
62
62
"invdtypes" ,
@@ -74,7 +74,11 @@ def test_and_shapes_invalid(invdtypes: dtype.Dtype) -> None:
74
74
75
75
result = wrapper .and_ (lhs , rhs )
76
76
77
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { invdtypes } " # noqa
77
+ assert (
78
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
79
+ ), f"failed for shape: { shape } and dtype { invdtypes } "
80
+
81
+
78
82
@pytest .mark .parametrize (
79
83
"shape" ,
80
84
[
@@ -88,14 +92,23 @@ def test_and_shapes_invalid(invdtypes: dtype.Dtype) -> None:
88
92
@pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
89
93
def test_bitand_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
90
94
"""Test bitand operation between two arrays of the same shape"""
91
- if dtype_name == dtype .c32 or dtype_name == dtype .c64 or dtype_name == dtype .f32 or dtype_name == dtype .f64 or dtype_name == dtype .f16 :
95
+ if (
96
+ dtype_name == dtype .c32
97
+ or dtype_name == dtype .c64
98
+ or dtype_name == dtype .f32
99
+ or dtype_name == dtype .f64
100
+ or dtype_name == dtype .f16
101
+ ):
92
102
pytest .skip ()
93
103
lhs = wrapper .randu (shape , dtype_name )
94
104
rhs = wrapper .randu (shape , dtype_name )
95
105
96
106
result = wrapper .bitand (lhs , rhs )
97
107
98
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
108
+ assert (
109
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
110
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
111
+
99
112
100
113
@pytest .mark .parametrize (
101
114
"invdtypes" ,
@@ -111,6 +124,8 @@ def test_bitand_shapes_invalid(invdtypes: dtype.Dtype) -> None:
111
124
lhs = wrapper .randu (shape , invdtypes )
112
125
rhs = wrapper .randu (shape , invdtypes )
113
126
wrapper .bitand (lhs , rhs )
127
+
128
+
114
129
@pytest .mark .parametrize (
115
130
"shape" ,
116
131
[
@@ -124,13 +139,22 @@ def test_bitand_shapes_invalid(invdtypes: dtype.Dtype) -> None:
124
139
@pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
125
140
def test_bitnot_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
126
141
"""Test bitnot operation between two arrays of the same shape"""
127
- if dtype_name == dtype .c32 or dtype_name == dtype .c64 or dtype_name == dtype .f32 or dtype_name == dtype .f64 or dtype_name == dtype .f16 :
142
+ if (
143
+ dtype_name == dtype .c32
144
+ or dtype_name == dtype .c64
145
+ or dtype_name == dtype .f32
146
+ or dtype_name == dtype .f64
147
+ or dtype_name == dtype .f16
148
+ ):
128
149
pytest .skip ()
129
150
out = wrapper .randu (shape , dtype_name )
130
151
131
152
result = wrapper .bitnot (out )
132
153
133
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
154
+ assert (
155
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
156
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
157
+
134
158
135
159
@pytest .mark .parametrize (
136
160
"invdtypes" ,
@@ -145,6 +169,8 @@ def test_bitnot_shapes_invalid(invdtypes: dtype.Dtype) -> None:
145
169
shape = (3 , 3 )
146
170
out = wrapper .randu (shape , invdtypes )
147
171
wrapper .bitnot (out )
172
+
173
+
148
174
@pytest .mark .parametrize (
149
175
"shape" ,
150
176
[
@@ -158,14 +184,23 @@ def test_bitnot_shapes_invalid(invdtypes: dtype.Dtype) -> None:
158
184
@pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
159
185
def test_bitor_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
160
186
"""Test bitor operation between two arrays of the same shape"""
161
- if dtype_name == dtype .c32 or dtype_name == dtype .c64 or dtype_name == dtype .f32 or dtype_name == dtype .f64 or dtype_name == dtype .f16 :
187
+ if (
188
+ dtype_name == dtype .c32
189
+ or dtype_name == dtype .c64
190
+ or dtype_name == dtype .f32
191
+ or dtype_name == dtype .f64
192
+ or dtype_name == dtype .f16
193
+ ):
162
194
pytest .skip ()
163
195
lhs = wrapper .randu (shape , dtype_name )
164
196
rhs = wrapper .randu (shape , dtype_name )
165
197
166
198
result = wrapper .bitor (lhs , rhs )
167
199
168
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
200
+ assert (
201
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
202
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
203
+
169
204
170
205
@pytest .mark .parametrize (
171
206
"invdtypes" ,
@@ -182,6 +217,7 @@ def test_bitor_shapes_invalid(invdtypes: dtype.Dtype) -> None:
182
217
rhs = wrapper .randu (shape , invdtypes )
183
218
wrapper .bitor (lhs , rhs )
184
219
220
+
185
221
@pytest .mark .parametrize (
186
222
"shape" ,
187
223
[
@@ -195,14 +231,23 @@ def test_bitor_shapes_invalid(invdtypes: dtype.Dtype) -> None:
195
231
@pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
196
232
def test_bitxor_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
197
233
"""Test bitxor operation between two arrays of the same shape"""
198
- if dtype_name == dtype .c32 or dtype_name == dtype .c64 or dtype_name == dtype .f32 or dtype_name == dtype .f64 or dtype_name == dtype .f16 :
234
+ if (
235
+ dtype_name == dtype .c32
236
+ or dtype_name == dtype .c64
237
+ or dtype_name == dtype .f32
238
+ or dtype_name == dtype .f64
239
+ or dtype_name == dtype .f16
240
+ ):
199
241
pytest .skip ()
200
242
lhs = wrapper .randu (shape , dtype_name )
201
243
rhs = wrapper .randu (shape , dtype_name )
202
244
203
245
result = wrapper .bitxor (lhs , rhs )
204
246
205
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
247
+ assert (
248
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
249
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
250
+
206
251
207
252
@pytest .mark .parametrize (
208
253
"invdtypes" ,
@@ -218,6 +263,8 @@ def test_bitxor_shapes_invalid(invdtypes: dtype.Dtype) -> None:
218
263
lhs = wrapper .randu (shape , invdtypes )
219
264
rhs = wrapper .randu (shape , invdtypes )
220
265
wrapper .bitxor (lhs , rhs )
266
+
267
+
221
268
@pytest .mark .parametrize (
222
269
"shape" ,
223
270
[
@@ -231,14 +278,23 @@ def test_bitxor_shapes_invalid(invdtypes: dtype.Dtype) -> None:
231
278
@pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
232
279
def test_eq_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
233
280
"""Test eq operation between two arrays of the same shape"""
234
- if dtype_name == dtype .c32 or dtype_name == dtype .c64 or dtype_name == dtype .f32 or dtype_name == dtype .f64 or dtype_name == dtype .f16 :
281
+ if (
282
+ dtype_name == dtype .c32
283
+ or dtype_name == dtype .c64
284
+ or dtype_name == dtype .f32
285
+ or dtype_name == dtype .f64
286
+ or dtype_name == dtype .f16
287
+ ):
235
288
pytest .skip ()
236
289
lhs = wrapper .randu (shape , dtype_name )
237
290
rhs = wrapper .randu (shape , dtype_name )
238
291
239
292
result = wrapper .eq (lhs , rhs )
240
293
241
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
294
+ assert (
295
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
296
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
297
+
242
298
243
299
@pytest .mark .parametrize (
244
300
"invdtypes" ,
@@ -254,6 +310,8 @@ def test_eq_shapes_invalid(invdtypes: dtype.Dtype) -> None:
254
310
lhs = wrapper .randu (shape , invdtypes )
255
311
rhs = wrapper .randu (shape , invdtypes )
256
312
wrapper .eq (lhs , rhs )
313
+
314
+
257
315
@pytest .mark .parametrize (
258
316
"shape" ,
259
317
[
@@ -272,7 +330,10 @@ def test_ge_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
272
330
273
331
result = wrapper .ge (lhs , rhs )
274
332
275
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
333
+ assert (
334
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
335
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
336
+
276
337
277
338
@pytest .mark .parametrize (
278
339
"invdtypes" ,
@@ -289,6 +350,7 @@ def test_ge_shapes_invalid(invdtypes: dtype.Dtype) -> None:
289
350
rhs = wrapper .randu (shape , invdtypes )
290
351
wrapper .ge (lhs , rhs )
291
352
353
+
292
354
@pytest .mark .parametrize (
293
355
"shape" ,
294
356
[
@@ -307,7 +369,10 @@ def test_gt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
307
369
308
370
result = wrapper .gt (lhs , rhs )
309
371
310
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
372
+ assert (
373
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
374
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
375
+
311
376
312
377
@pytest .mark .parametrize (
313
378
"invdtypes" ,
@@ -324,6 +389,7 @@ def test_gt_shapes_invalid(invdtypes: dtype.Dtype) -> None:
324
389
rhs = wrapper .randu (shape , invdtypes )
325
390
wrapper .gt (lhs , rhs )
326
391
392
+
327
393
@pytest .mark .parametrize (
328
394
"shape" ,
329
395
[
@@ -342,7 +408,10 @@ def test_le_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
342
408
343
409
result = wrapper .le (lhs , rhs )
344
410
345
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
411
+ assert (
412
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
413
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
414
+
346
415
347
416
@pytest .mark .parametrize (
348
417
"invdtypes" ,
@@ -358,6 +427,8 @@ def test_le_shapes_invalid(invdtypes: dtype.Dtype) -> None:
358
427
lhs = wrapper .randu (shape , invdtypes )
359
428
rhs = wrapper .randu (shape , invdtypes )
360
429
wrapper .le (lhs , rhs )
430
+
431
+
361
432
@pytest .mark .parametrize (
362
433
"shape" ,
363
434
[
@@ -376,7 +447,10 @@ def test_lt_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
376
447
377
448
result = wrapper .lt (lhs , rhs )
378
449
379
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
450
+ assert (
451
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
452
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
453
+
380
454
381
455
@pytest .mark .parametrize (
382
456
"invdtypes" ,
@@ -392,6 +466,8 @@ def test_lt_shapes_invalid(invdtypes: dtype.Dtype) -> None:
392
466
lhs = wrapper .randu (shape , invdtypes )
393
467
rhs = wrapper .randu (shape , invdtypes )
394
468
wrapper .lt (lhs , rhs )
469
+
470
+
395
471
@pytest .mark .parametrize (
396
472
"shape" ,
397
473
[
@@ -410,7 +486,10 @@ def test_neq_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
410
486
411
487
result = wrapper .neq (lhs , rhs )
412
488
413
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
489
+ assert (
490
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
491
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
492
+
414
493
415
494
@pytest .mark .parametrize (
416
495
"invdtypes" ,
@@ -426,6 +505,8 @@ def test_neq_shapes_invalid(invdtypes: dtype.Dtype) -> None:
426
505
lhs = wrapper .randu (shape , invdtypes )
427
506
rhs = wrapper .randu (shape , invdtypes )
428
507
wrapper .neq (lhs , rhs )
508
+
509
+
429
510
@pytest .mark .parametrize (
430
511
"shape" ,
431
512
[
@@ -439,13 +520,22 @@ def test_neq_shapes_invalid(invdtypes: dtype.Dtype) -> None:
439
520
@pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
440
521
def test_not_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
441
522
"""Test not operation between two arrays of the same shape"""
442
- if dtype_name == dtype .c32 or dtype_name == dtype .c64 or dtype_name == dtype .f32 or dtype_name == dtype .f64 or dtype_name == dtype .f16 :
523
+ if (
524
+ dtype_name == dtype .c32
525
+ or dtype_name == dtype .c64
526
+ or dtype_name == dtype .f32
527
+ or dtype_name == dtype .f64
528
+ or dtype_name == dtype .f16
529
+ ):
443
530
pytest .skip ()
444
531
out = wrapper .randu (shape , dtype_name )
445
532
446
533
result = wrapper .not_ (out )
447
534
448
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
535
+ assert (
536
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
537
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
538
+
449
539
450
540
@pytest .mark .parametrize (
451
541
"invdtypes" ,
@@ -460,6 +550,8 @@ def test_not_shapes_invalid(invdtypes: dtype.Dtype) -> None:
460
550
shape = (3 , 3 )
461
551
out = wrapper .randu (shape , invdtypes )
462
552
wrapper .not_ (out )
553
+
554
+
463
555
@pytest .mark .parametrize (
464
556
"shape" ,
465
557
[
@@ -478,7 +570,10 @@ def test_or_shape_dtypes(shape: tuple, dtype_name: dtype.Dtype) -> None:
478
570
479
571
result = wrapper .or_ (lhs , rhs )
480
572
481
- assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
573
+ assert (
574
+ wrapper .get_dims (result )[0 : len (shape )] == shape # noqa
575
+ ), f"failed for shape: { shape } and dtype { dtype_name } "
576
+
482
577
483
578
@pytest .mark .parametrize (
484
579
"invdtypes" ,
@@ -493,4 +588,4 @@ def test_or_shapes_invalid(invdtypes: dtype.Dtype) -> None:
493
588
shape = (3 , 3 )
494
589
lhs = wrapper .randu (shape , invdtypes )
495
590
rhs = wrapper .randu (shape , invdtypes )
496
- wrapper .or_ (lhs , rhs )
591
+ wrapper .or_ (lhs , rhs )
0 commit comments