Skip to content

Commit 10757d1

Browse files
committed
lookup + faster not
1 parent 320f9fc commit 10757d1

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

arrayfire/array.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,9 @@ def __invert__(self):
10081008
"""
10091009
Return ~self
10101010
"""
1011-
return self == 0
1011+
out = Array()
1012+
safe_call(backend.get().af_not(c_pointer(out.arr), self.arr))
1013+
self = out
10121014

10131015
def __nonzero__(self):
10141016
return self != 0

arrayfire/data.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,3 +799,46 @@ def replace(lhs, cond, rhs):
799799
safe_call(backend.get().af_replace(lhs.arr, cond.arr, rhs.arr))
800800
else:
801801
safe_call(backend.get().af_replace_scalar(lhs.arr, cond.arr, c_double_t(rhs)))
802+
803+
def lookup(a, idx, dim=0):
804+
"""
805+
Lookup the values of input array based on index.
806+
807+
Parameters
808+
----------
809+
810+
a : af.Array.
811+
Multi dimensional array.
812+
813+
idx : is lookup indices
814+
815+
dim : optional: int. default: 0.
816+
Specifies the dimension for indexing
817+
818+
Returns
819+
-------
820+
821+
out : af.Array
822+
An array containing values at locations specified by 'idx'
823+
824+
Examples
825+
---------
826+
827+
>>> import arrayfire as af
828+
>>> a = af.randu(3, 3)
829+
>>> af.display(a)
830+
[3 3 1 1]
831+
0.7269 0.3569 0.3341
832+
0.7104 0.1437 0.0899
833+
0.5201 0.4563 0.5363
834+
835+
>>> idx = af.array([1, 2])
836+
>>> o = af.lookup()
837+
[2 1 1 1]
838+
0.7269 0.3569 0.3341
839+
0.7104 0.1437 0.0899
840+
841+
"""
842+
out = Array()
843+
safe_call(backend.get().af_lookup(c_pointer(out.arr), a.arr, idx.arr, c_int_t(dim)))
844+
return out

0 commit comments

Comments
 (0)