[python-arrayfire] 123/250: Correctly calculate dimensions for assignments with boolean keys
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Mar 28 22:59:39 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 da82001d649e4c99f5f2b1f0847f189503fae8d6
Author: Filipe Maia <filipe.c.maia at gmail.com>
Date: Tue Nov 3 15:20:05 2015 +0100
Correctly calculate dimensions for assignments with boolean keys
---
arrayfire/array.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/arrayfire/array.py b/arrayfire/array.py
index be0dad7..3baf75e 100644
--- a/arrayfire/array.py
+++ b/arrayfire/array.py
@@ -19,6 +19,7 @@ from .bcast import _bcast_var
from .base import *
from .index import *
from .index import _Index4
+from .algorithm import sum
def _create_array(buf, numdims, idims, dtype):
out_arr = ct.c_void_p(0)
@@ -182,8 +183,12 @@ def _get_assign_dims(key, idims):
elif isinstance(key, ParallelRange):
dims[0] = _slice_to_length(key.S, idims[0])
return dims
- elif isinstance(key, BaseArray):
- dims[0] = key.elements()
+ elif isinstance(key, BaseArray):
+ # If the array is boolean take only the number of nonzeros
+ if(key.dtype() is Dtype.b8):
+ dims[0] = int(sum(key))
+ else:
+ dims[0] = key.elements()
return dims
elif isinstance(key, tuple):
n_inds = len(key)
@@ -192,7 +197,11 @@ def _get_assign_dims(key, idims):
if (_is_number(key[n])):
dims[n] = 1
elif (isinstance(key[n], BaseArray)):
- dims[n] = key[n].elements()
+ # If the array is boolean take only the number of nonzeros
+ if(key[n].dtype() is Dtype.b8):
+ dims[n] = int(sum(key[n]))
+ else:
+ dims[n] = key[n].elements()
elif (isinstance(key[n], slice)):
dims[n] = _slice_to_length(key[n], idims[n])
elif (isinstance(key[n], ParallelRange)):
--
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