Skip to content

Commit

Permalink
npbackend: Added np.sign.
Browse files Browse the repository at this point in the history
  • Loading branch information
safl committed Apr 16, 2015
1 parent 1637e86 commit 88ce4f1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bridge/npbackend/ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,18 @@ def __call__(self, ary, out=None):
out[...] = -1 * ary
return out

UFUNCS = [Negative({'name':'negative'})] # Expose via UFUNCS
class Sign(Ufunc):
def __call__(self, ary, out=None):
if out is None:
return (ary < 0)*ary.dtype.type(-1) + (ary>0)*ary.dtype.type(1)
else:
out[...] = (ary < 0)*ary.dtype.type(-1) + (ary>0)*ary.dtype.type(1)
return out

UFUNCS = [
Negative({'name':'negative'}),
Sign({'name':'sign'})
] # Expose via UFUNCS
for op in _info.op.itervalues():
UFUNCS.append(Ufunc(op))

Expand Down

0 comments on commit 88ce4f1

Please sign in to comment.