forked from arrayfire/arrayfire-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdtypes.py
More file actions
109 lines (98 loc) · 1.51 KB
/
dtypes.py
File metadata and controls
109 lines (98 loc) · 1.51 KB
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
__all__ = [
"Dtype",
"b8",
"bool",
"c32",
"c64",
"complex32",
"complex64",
"f16",
"f32",
"f64",
"float16",
"float32",
"float64",
"int16",
"int32",
"int64",
"s16",
"s32",
"s64",
"u8",
"u16",
"u32",
"u64",
"uint8",
"uint16",
"uint32",
"uint64",
]
from typing import TypeAlias
py_bool: TypeAlias = bool
from arrayfire_wrapper import ( # noqa
Dtype,
b8,
bool,
c32,
c64,
complex32,
complex64,
f16,
f32,
f64,
float16,
float32,
float64,
int16,
int32,
int64,
s16,
s32,
s64,
u8,
u16,
u32,
u64,
uint8,
uint16,
uint32,
uint64,
)
supported_dtypes = (
int16,
int32,
int64,
uint8,
uint16,
uint32,
uint64,
float16,
float32,
float64,
complex64,
complex32,
bool,
s16,
s32,
s64,
u8,
u16,
u32,
u64,
f16,
f32,
f64,
c32,
c64,
b8,
)
def c_api_value_to_dtype(value: int) -> Dtype:
for dtype in supported_dtypes:
if value == dtype.c_api_value:
return dtype
raise TypeError("There is no supported dtype that matches passed dtype C API value.")
def str_to_dtype(value: str) -> Dtype:
for dtype in supported_dtypes:
if value == dtype.typecode or value == dtype.typename or value == dtype.name:
return dtype
raise TypeError("There is no supported dtype that matches passed dtype typecode.")