Skip to content

Commit 2a52463

Browse files
committed
BUGFIX: indexing with boolean arrays
1 parent ce1ae09 commit 2a52463

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

arrayfire/index.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,24 @@ def __init__ (self, idx):
192192
self.isSeq = True
193193

194194
if isinstance(idx, BaseArray):
195-
self.idx.arr = idx.arr
195+
196+
arr = ct.c_void_p(0)
197+
198+
if (Enum_value(idx.dtype()) ==
199+
Enum_value(Dtype.b8)):
200+
safe_call(backend.get().af_where(ct.pointer(arr), idx.arr))
201+
else:
202+
safe_call(backend.get().af_retain_array(ct.pointer(arr), idx.arr))
203+
204+
self.idx.arr = arr
196205
self.isSeq = False
197206
elif isinstance(idx, ParallelRange):
198207
self.idx.seq = idx
199208
self.isBatch = True
200209
else:
201210
self.idx.seq = Seq(idx)
211+
212+
# def __del__(self):
213+
# if not self.isSeq:
214+
# arr = self.idx.arr
215+
# backend.get().af_release_array(arr)

tests/simple_index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,10 @@
6666
for r in rows:
6767
af.display(r)
6868
af.display(b[:,r])
69+
70+
a = af.randu(3)
71+
c = af.randu(3)
72+
b = af.constant(1,3,dtype=af.Dtype.b8)
73+
af.display(a)
74+
a[b] = c
75+
af.display(a)

0 commit comments

Comments
 (0)