FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
arrayfire-binary-python-wrapper/tests/test_constants.py at master · arrayfire/arrayfire-binary-python-wrapper · GitHub
arrayfire
arrayfire-binary-python-wrapper
Repository navigation
Code
Issues
1
(1)
Pull requests
2
(2)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
arrayfire-binary-python-wrapper
/
tests
/
test_constants.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
246 lines (191 loc) · 7.08 KB
Breadcrumbs
arrayfire-binary-python-wrapper
/
tests
/
test_constants.py
Copy path
File metadata and controls
246 lines (191 loc) · 7.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import
random
import
pytest
import
arrayfire_wrapper
.
lib
as
wrapper
from
arrayfire_wrapper
.
dtypes
import
(
Dtype
,
c32
,
c64
,
c_api_value_to_dtype
,
f16
,
f32
,
f64
,
s16
,
s32
,
s64
,
u8
,
u16
,
u32
,
u64
,
)
invalid_shape
=
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
)
all_types
=
[
s16
,
s32
,
s64
,
u8
,
u16
,
u32
,
u64
,
f16
,
f32
,
f64
,
c32
,
c64
]
@
pytest
.
mark
.
parametrize
(
"shape"
,
[
(),
(
random
.
randint
(
1
,
10
),
1
),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
],
)
def
test_constant_shape
(
shape
:
tuple
)
->
None
:
"""Test if constant creates an array with the correct shape."""
number
=
5.0
dtype
=
s16
result
=
wrapper
.
constant
(
number
,
shape
,
dtype
)
assert
wrapper
.
get_dims
(
result
)[
0
:
len
(
shape
)]
==
shape
# noqa: E203
@
pytest
.
mark
.
parametrize
(
"shape"
,
[
(),
(
random
.
randint
(
1
,
10
),
1
),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
],
)
def
test_constant_complex_shape
(
shape
:
tuple
)
->
None
:
"""Test if constant_complex creates an array with the correct shape."""
dtype
=
c32
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
number
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
if
isinstance
(
number
, (
complex
)):
result
=
wrapper
.
constant_complex
(
number
,
shape
,
dtype
)
assert
wrapper
.
get_dims
(
result
)[
0
:
len
(
shape
)]
==
shape
# noqa: E203
else
:
pytest
.
skip
()
@
pytest
.
mark
.
parametrize
(
"shape"
,
[
(),
(
random
.
randint
(
1
,
10
),
1
),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
],
)
def
test_constant_long_shape
(
shape
:
tuple
)
->
None
:
"""Test if constant_long creates an array with the correct shape."""
dtype
=
s64
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
number
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
if
isinstance
(
number
, (
int
,
float
)):
result
=
wrapper
.
constant_long
(
number
,
shape
,
dtype
)
assert
wrapper
.
get_dims
(
result
)[
0
:
len
(
shape
)]
==
shape
# noqa: E203
@
pytest
.
mark
.
parametrize
(
"shape"
,
[
(),
(
random
.
randint
(
1
,
10
),
1
),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
(
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
),
random
.
randint
(
1
,
10
)),
],
)
def
test_constant_ulong_shape
(
shape
:
tuple
)
->
None
:
"""Test if constant_ulong creates an array with the correct shape."""
dtype
=
u64
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
number
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
if
isinstance
(
number
, (
int
,
float
)):
result
=
wrapper
.
constant_ulong
(
number
,
shape
,
dtype
)
assert
wrapper
.
get_dims
(
result
)[
0
:
len
(
shape
)]
==
shape
# noqa: E203
else
:
pytest
.
skip
()
def
test_constant_shape_invalid
()
->
None
:
"""Test if constant handles a shape with greater than 4 dimensions"""
with
pytest
.
raises
(
TypeError
):
number
=
5.0
dtype
=
s16
wrapper
.
constant
(
number
,
invalid_shape
,
dtype
)
def
test_constant_complex_shape_invalid
()
->
None
:
"""Test if constant_complex handles a shape with greater than 4 dimensions"""
with
pytest
.
raises
(
TypeError
):
dtype
=
c32
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
number
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
if
isinstance
(
number
, (
int
,
float
,
complex
)):
wrapper
.
constant_complex
(
number
,
invalid_shape
,
dtype
)
def
test_constant_long_shape_invalid
()
->
None
:
"""Test if constant_long handles a shape with greater than 4 dimensions"""
with
pytest
.
raises
(
TypeError
):
dtype
=
s64
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
number
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
if
isinstance
(
number
, (
int
,
float
)):
wrapper
.
constant_long
(
number
,
invalid_shape
,
dtype
)
def
test_constant_ulong_shape_invalid
()
->
None
:
"""Test if constant_ulong handles a shape with greater than 4 dimensions"""
with
pytest
.
raises
(
TypeError
):
dtype
=
u64
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
number
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
if
isinstance
(
number
, (
int
,
float
)):
wrapper
.
constant_ulong
(
number
,
invalid_shape
,
dtype
)
@
pytest
.
mark
.
parametrize
(
"dtype"
,
all_types
,
)
def
test_constant_dtype
(
dtype
:
Dtype
)
->
None
:
"""Test if constant creates an array with the correct dtype."""
if
is_cmplx_type
(
dtype
)
or
not
is_system_supported
(
dtype
):
pytest
.
skip
()
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
value
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
shape
=
(
2
,
2
)
if
isinstance
(
value
, (
int
,
float
)):
result
=
wrapper
.
constant
(
value
,
shape
,
dtype
)
assert
c_api_value_to_dtype
(
wrapper
.
get_type
(
result
))
==
dtype
else
:
pytest
.
skip
()
@
pytest
.
mark
.
parametrize
(
"dtype"
,
all_types
,
)
def
test_constant_complex_dtype
(
dtype
:
Dtype
)
->
None
:
"""Test if constant_complex creates an array with the correct dtype."""
if
not
is_cmplx_type
(
dtype
)
or
not
is_system_supported
(
dtype
):
pytest
.
skip
()
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
value
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
shape
=
(
2
,
2
)
if
isinstance
(
value
, (
int
,
float
,
complex
)):
result
=
wrapper
.
constant_complex
(
value
,
shape
,
dtype
)
assert
c_api_value_to_dtype
(
wrapper
.
get_type
(
result
))
==
dtype
else
:
pytest
.
skip
()
def
test_constant_long_dtype
()
->
None
:
"""Test if constant_long creates an array with the correct dtype."""
dtype
=
s64
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
value
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
shape
=
(
2
,
2
)
if
isinstance
(
value
, (
int
,
float
)):
result
=
wrapper
.
constant_long
(
value
,
shape
,
dtype
)
assert
c_api_value_to_dtype
(
wrapper
.
get_type
(
result
))
==
dtype
else
:
pytest
.
skip
()
def
test_constant_ulong_dtype
()
->
None
:
"""Test if constant_ulong creates an array with the correct dtype."""
dtype
=
u64
rand_array
=
wrapper
.
randu
((
1
,
1
),
dtype
)
value
=
wrapper
.
get_scalar
(
rand_array
,
dtype
)
shape
=
(
2
,
2
)
if
isinstance
(
value
, (
int
,
float
)):
result
=
wrapper
.
constant_ulong
(
value
,
shape
,
dtype
)
assert
c_api_value_to_dtype
(
wrapper
.
get_type
(
result
))
==
dtype
else
:
pytest
.
skip
()
def
is_cmplx_type
(
dtype
:
Dtype
)
->
bool
:
return
dtype
==
c32
or
dtype
==
c64
def
is_system_supported
(
dtype
:
Dtype
)
->
bool
:
if
dtype
in
[
f64
,
c64
]
and
not
wrapper
.
get_dbl_support
():
return
False
return
True
Back
|
FazBrowse Home
|
New Git URL