Skip to content

Commit eb12c2b

Browse files
authored
Merge pull request arrayfire#112 from unbornchikken/pr1
missing functions: lookup and not
2 parents 7465f50 + 4237ffb commit eb12c2b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

arrayfire/array.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,10 @@ 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
1014+
return self
10121015

10131016
def __nonzero__(self):
10141017
return self != 0

arrayfire/data.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,3 +799,50 @@ 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+
>>> arr = af.Array([1,0,3,4,5,6], (2,3))
829+
>>> af.display(arr)
830+
[2 3 1 1]
831+
1.0000 3.0000 5.0000
832+
0.0000 4.0000 6.0000
833+
834+
>>> idx = af.array([0, 2])
835+
>>> af.lookup(arr, idx, 1)
836+
[2 2 1 1]
837+
1.0000 5.0000
838+
0.0000 6.0000
839+
840+
>>> idx = af.array([0])
841+
>>> af.lookup(arr, idx, 0)
842+
[2 1 1 1]
843+
0.0000
844+
2.0000
845+
"""
846+
out = Array()
847+
safe_call(backend.get().af_lookup(c_pointer(out.arr), a.arr, idx.arr, c_int_t(dim)))
848+
return out

0 commit comments

Comments
 (0)