Skip to content

Commit 17e500a

Browse files
committed
implement unary ops
1 parent 11ce1a1 commit 17e500a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

larray/core.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,11 +1399,21 @@ def opmethod(self, other):
13991399
__or__ = _binop('or')
14001400
__ror__ = _binop('ror')
14011401

1402+
# element-wise method factory
1403+
def _unaryop(opname):
1404+
fullname = '__%s__' % opname
1405+
super_method = getattr(np.ndarray, fullname)
1406+
1407+
def opmethod(self):
1408+
return LArray(super_method(self.data), self.axes)
1409+
opmethod.__name__ = fullname
1410+
return opmethod
1411+
14021412
# unary ops do not need broadcasting so do not need to be overridden
1403-
# __neg__ = _unaryop('neg')
1404-
# __pos__ = _unaryop('pos')
1405-
# __abs__ = _unaryop('abs')
1406-
# __invert__ = _unaryop('invert')
1413+
__neg__ = _unaryop('neg')
1414+
__pos__ = _unaryop('pos')
1415+
__abs__ = _unaryop('abs')
1416+
__invert__ = _unaryop('invert')
14071417

14081418
def append(self, **kwargs):
14091419
label = kwargs.pop('label', None)

0 commit comments

Comments
 (0)