[python-arrayfire] 216/250: Enabling to pass offset and strides to the array constructor
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:50 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 cf28938162f8d25be3dfa0bcb8f6dfe3fd5339c1
Author: Filipe Maia <filipe.c.maia at gmail.com>
Date: Sun Feb 14 15:16:03 2016 +0100
Enabling to pass offset and strides to the array constructor
---
arrayfire/array.py | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index cb64659..d413a2d 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -31,6 +31,27 @@ def _create_array(buf, numdims, idims, dtype, is_device):
numdims, ct.pointer(c_dims), dtype.value))
return out_arr
+def _create_strided_array(buf, numdims, idims, dtype, is_device, offset, strides):
+ out_arr = ct.c_void_p(0)
+ c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
+ if offset is None:
+ offset = 0
+ offset = ct.c_ulonglong(offset)
+ if strides is None:
+ strides = (1, idims[0], idims[0]*idims[1], idims[0]*idims[1]*idims[2])
+ while len(strides) < 4:
+ strides = strides + (strides[-1],)
+ strides = dim4(strides[0], strides[1], strides[2], strides[3])
+ if is_device:
+ location = Source.device
+ else:
+ location = Source.host
+ safe_call(backend.get().af_create_strided_array(ct.pointer(out_arr), ct.c_void_p(buf),
+ offset, numdims, ct.pointer(c_dims),
+ ct.pointer(strides), dtype.value,
+ location.value))
+ return out_arr
+
def _create_empty_array(numdims, idims, dtype):
out_arr = ct.c_void_p(0)
c_dims = dim4(idims[0], idims[1], idims[2], idims[3])
@@ -352,7 +373,7 @@ class Array(BaseArray):
"""
- def __init__(self, src=None, dims=(0,), dtype=None, is_device=False):
+ def __init__(self, src=None, dims=(0,), dtype=None, is_device=False, offset=None, strides=None):
super(Array, self).__init__()
@@ -409,8 +430,10 @@ class Array(BaseArray):
if (type_char is not None and
type_char != _type_char):
raise TypeError("Can not create array of requested type from input data type")
-
- self.arr = _create_array(buf, numdims, idims, to_dtype[_type_char], is_device)
+ if(offset is None and strides is None):
+ self.arr = _create_array(buf, numdims, idims, to_dtype[_type_char], is_device)
+ else:
+ self.arr = _create_strided_array(buf, numdims, idims, to_dtype[_type_char], is_device, offset, strides)
else:
--
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