Skip to content

Commit d8ddc4c

Browse files
committed
MAINT: ndarray.__bitwise_ops__
1 parent 39248a1 commit d8ddc4c

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

torch_np/_ndarray.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,36 @@ def __imod__(self, other):
259259
return _ufunc_impl.remainder(self, asarray(other), out=self)
260260

261261

262+
# bitwise ops
263+
# and, self & other
264+
def __and__(self, other):
265+
return _ufunc_impl.bitwise_and(self, asarray(other))
262266

267+
def __rand__(self, other):
268+
return _ufunc_impl.bitwise_and(self, asarray(other))
263269

264-
# FIXME ops and binops below
270+
def __iand__(self, other):
271+
return _ufunc_impl.bitwise_and(self, asarray(other), out=self)
265272

273+
# or, self | other
266274
def __or__(self, other):
267-
other_tensor = asarray(other).get()
268-
return asarray(self._tensor.__or__(other_tensor))
275+
return _ufunc_impl.bitwise_or(self, asarray(other))
276+
277+
def __ror__(self, other):
278+
return _ufunc_impl.bitwise_or(self, asarray(other))
269279

270280
def __ior__(self, other):
271-
other_tensor = asarray(other).get()
272-
return asarray(self._tensor.__ior__(other_tensor))
281+
return _ufunc_impl.bitwise_or(self, asarray(other), out=self)
282+
283+
# xor, self ^ other
284+
def __xor__(self, other):
285+
return _ufunc_impl.bitwise_xor(self, asarray(other))
286+
287+
def __rxor__(self, other):
288+
return _ufunc_impl.bitwise_xor(self, asarray(other))
289+
290+
def __ixor__(self, other):
291+
return _ufunc_impl.bitwise_xor(self, asarray(other), out=self)
273292

274293

275294
# unary ops

0 commit comments

Comments
 (0)