Skip to content

Commit 2196fe5

Browse files
committed
BUGFIX: Fix conversion between numpy and arrayfire arrays
1 parent 7b30010 commit 2196fe5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

arrayfire/interop.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626

2727
AF_NUMPY_FOUND=True
2828

29+
_nptype_to_aftype = {'f4' : Dtype.f32,
30+
'f8' : Dtype.f64,
31+
'b1' : Dtype.b8,
32+
'u1' : Dtype.u8,
33+
'i4' : Dtype.s32,
34+
's4' : Dtype.u32,
35+
'i8' : Dtype.s64,
36+
's8' : Dtype.u64,
37+
'c8' : Dtype.c32,
38+
'c16' : Dtype.c64}
39+
40+
2941
def np_to_af_array(np_arr):
3042
"""
3143
Convert numpy.ndarray to arrayfire.Array.
@@ -41,7 +53,7 @@ def np_to_af_array(np_arr):
4153

4254
in_shape = np_arr.shape
4355
in_ptr = np_arr.ctypes.data_as(ct.c_void_p)
44-
in_dtype = np_arr.dtype.char
56+
in_dtype = _nptype_to_aftype[np_arr.dtype.str[1:]]
4557

4658
if (np_arr.flags['F_CONTIGUOUS']):
4759
return Array(in_ptr, in_shape, in_dtype)

0 commit comments

Comments
 (0)