1+ import random
2+
3+ import numpy as np
4+ import pytest
5+
6+ import arrayfire_wrapper .dtypes as dtype
7+ import arrayfire_wrapper .lib as wrapper
8+
9+ from arrayfire_wrapper .lib .create_and_modify_array .helper_functions import array_to_string
10+
11+ dtype_map = {
12+ "int16" : dtype .s16 ,
13+ "int32" : dtype .s32 ,
14+ "int64" : dtype .s64 ,
15+ "uint8" : dtype .u8 ,
16+ "uint16" : dtype .u16 ,
17+ "uint32" : dtype .u32 ,
18+ "uint64" : dtype .u64 ,
19+ "float16" : dtype .f16 ,
20+ "float32" : dtype .f32 ,
21+ # 'float64': dtype.f64,
22+ # 'complex64': dtype.c64,
23+ "complex32" : dtype .c32 ,
24+ "bool" : dtype .b8 ,
25+ "s16" : dtype .s16 ,
26+ "s32" : dtype .s32 ,
27+ "s64" : dtype .s64 ,
28+ "u8" : dtype .u8 ,
29+ "u16" : dtype .u16 ,
30+ "u32" : dtype .u32 ,
31+ "u64" : dtype .u64 ,
32+ "f16" : dtype .f16 ,
33+ "f32" : dtype .f32 ,
34+ # 'f64': dtype.f64,
35+ "c32" : dtype .c32 ,
36+ # 'c64': dtype.c64,
37+ "b8" : dtype .b8 ,
38+ }
39+
40+
41+ @pytest .mark .parametrize (
42+ "shape" ,
43+ [
44+ (),
45+ (random .randint (1 , 10 ),),
46+ (random .randint (1 , 10 ), random .randint (1 , 10 )),
47+ (random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
48+ (random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
49+ ],
50+ )
51+ @pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
52+ def test_and_shape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
53+ """Test and_ operation between two arrays of the same shape"""
54+ lhs = wrapper .randu (shape , dtype_name )
55+ rhs = wrapper .randu (shape , dtype_name )
56+
57+ result = wrapper .and_ (lhs , rhs )
58+
59+ assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
60+
61+ @pytest .mark .parametrize (
62+ "invdtypes" ,
63+ [
64+ dtype .c64 ,
65+ dtype .f64 ,
66+ ],
67+ )
68+ def test_and_shapes_invalid (invdtypes : dtype .Dtype ) -> None :
69+ """Test and_ operation between two arrays of the same shape"""
70+ with pytest .raises (RuntimeError ):
71+ shape = (3 , 3 )
72+ lhs = wrapper .randu (shape , invdtypes )
73+ rhs = wrapper .randu (shape , invdtypes )
74+
75+ result = wrapper .and_ (lhs , rhs )
76+
77+ assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { invdtypes } " # noqa
78+ @pytest .mark .parametrize (
79+ "shape" ,
80+ [
81+ (),
82+ (random .randint (1 , 10 ),),
83+ (random .randint (1 , 10 ), random .randint (1 , 10 )),
84+ (random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
85+ (random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 ), random .randint (1 , 10 )),
86+ ],
87+ )
88+ @pytest .mark .parametrize ("dtype_name" , dtype_map .values ())
89+ def test_bitandshape_dtypes (shape : tuple , dtype_name : dtype .Dtype ) -> None :
90+ """Test bitand operation between two arrays of the same shape"""
91+ print (dtype_name )
92+ 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 :
93+ pytest .skip ()
94+ lhs = wrapper .randu (shape , dtype_name )
95+ rhs = wrapper .randu (shape , dtype_name )
96+
97+ result = wrapper .bitand (lhs , rhs )
98+
99+ assert wrapper .get_dims (result )[0 : len (shape )] == shape , f"failed for shape: { shape } and dtype { dtype_name } " # noqa
100+
101+ @pytest .mark .parametrize (
102+ "invdtypes" ,
103+ [
104+ dtype .c64 ,
105+ dtype .f64 ,
106+ ],
107+ )
108+ def test_bitandshapes_invalid (invdtypes : dtype .Dtype ) -> None :
109+ """Test bitand operation between two arrays of the same shape"""
110+ with pytest .raises (RuntimeError ):
111+ shape = (3 , 3 )
112+ lhs = wrapper .randu (shape , invdtypes )
113+ rhs = wrapper .randu (shape , invdtypes )
0 commit comments