[python-arrayfire] 06/250: Add the ability to construct af.array from array.array
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:25 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository python-arrayfire.
commit 4cb7daa52d1db4a00646591cb4ba1bcf86c54fda
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Fri Jun 19 15:09:18 2015 -0400
Add the ability to construct af.array from array.array
---
arrayfire/array.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index d463944..61dfdd6 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -1,10 +1,67 @@
+import array as host
from .library import *
+from .util import dim4
+
+def create_array(buf, numdims, idims, dtype):
+ out_arr = c_longlong(0)
+ c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
+ clib.af_create_array(pointer(out_arr), c_longlong(buf), numdims, pointer(c_dims), dtype)
+ return out_arr
class array(object):
- def __init__(self):
+ def __init__(self, src=None, dims=(0,)):
+
self.arr = c_longlong(0)
+ buf=None
+ buf_len=0
+ type_char='f'
+ dtype = f32
+
+ if src is not None:
+
+ if isinstance(src, host.array):
+ buf,buf_len = src.buffer_info()
+ type_char = src.typecode
+ elif isinstance(src, list):
+ tmp = host.array('f', src)
+ buf,buf_len = tmp.buffer_info()
+ type_char = tmp.typecode
+ else:
+ raise TypeError("src is an object of unsupported class")
+
+ elements = 1
+ numdims = len(dims)
+ idims = [1]*4
+
+ for i in range(numdims):
+ elements *= dims[i]
+ idims[i] = dims[i]
+
+ if (elements == 0):
+ idims = [buf_len, 1, 1, 1]
+ numdims = 1
+
+ if type_char == 'f':
+ dtype = f32
+ elif type_char == 'd':
+ dtype = f64
+ elif type_char == 'b':
+ dtype = b8
+ elif type_char == 'B':
+ dtype = u8
+ elif type_char == 'i':
+ dtype = s32
+ elif type_char == 'I':
+ dtype = u32
+ elif type_char == 'l':
+ dtype = s64
+ elif type_char == 'L':
+ dtype = u64
+
+ self.arr = create_array(buf, numdims, idims, dtype)
+
def __del__(self):
if (self.arr.value != 0):
clib.af_release_array(self.arr)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-arrayfire.git
More information about the debian-science-commits
mailing list