Skip to content

Commit 80ab970

Browse files
committed
Simplifying the array constructor using python maps
1 parent c06153d commit 80ab970

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

arrayfire/array.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,7 @@ def __init__(self, src=None, dims=(0,)):
105105
idims = [buf_len, 1, 1, 1]
106106
numdims = 1
107107

108-
if type_char == 'f':
109-
dtype = f32
110-
elif type_char == 'd':
111-
dtype = f64
112-
elif type_char == 'b':
113-
dtype = b8
114-
elif type_char == 'B':
115-
dtype = u8
116-
elif type_char == 'i':
117-
dtype = s32
118-
elif type_char == 'I':
119-
dtype = u32
120-
elif type_char == 'l':
121-
dtype = s64
122-
elif type_char == 'L':
123-
dtype = u64
108+
dtype = to_dtype[type_char]
124109

125110
self.arr = create_array(buf, numdims, idims, dtype)
126111

arrayfire/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,13 @@ def safe_call(af_error):
3030
c_err_len = c_longlong(0)
3131
clib.af_get_last_error(pointer(c_err_str), pointer(c_err_len))
3232
raise RuntimeError(to_str(c_err_str), af_error)
33+
34+
35+
to_dtype = {'f' : f32,
36+
'd' : f64,
37+
'b' : b8,
38+
'B' : u8,
39+
'i' : s32,
40+
'I' : u32,
41+
'l' : s64,
42+
'L' : u64}

0 commit comments

Comments
 (0)