Skip to content

Commit

Permalink
Add dunder methods for or and and operations
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed May 24, 2024
1 parent 632a246 commit 268d8dc
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/delayedarray/DelayedArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,66 @@ def __abs__(self) -> "DelayedArray":
"""
return DelayedArray(UnaryIsometricOpSimple(self._seed, operation="abs"))

def __or__(self, other) -> "DelayedArray":
"""Element-wise OR with something.
Args:
other:
A numeric scalar;
or a NumPy array with dimensions as described in
:py:class:`~delayedarray.UnaryIsometricOpWithArgs.UnaryIsometricOpWithArgs`;
or a ``DelayedArray`` of the same dimensions as :py:attr:`~shape`.
Returns:
A ``DelayedArray`` containing the delayed OR operation.
"""
return _wrap_isometric_with_args(self, other, operation="logical_or", right=True)

def __ror__(self, other) -> "DelayedArray":
"""Element-wise OR with the right-hand-side of a ``DelayedArray``.
Args:
other:
A numeric scalar;
or a NumPy array with dimensions as described in
:py:class:`~delayedarray.UnaryIsometricOpWithArgs.UnaryIsometricOpWithArgs`;
or a ``DelayedArray`` of the same dimensions as :py:attr:`~shape`.
Returns:
A ``DelayedArray`` containing the delayed OR operation.
"""
return _wrap_isometric_with_args(self, other, operation="logical_or", right=False)

def __and__(self, other) -> "DelayedArray":
"""Element-wise AND with something.
Args:
other:
A numeric scalar;
or a NumPy array with dimensions as described in
:py:class:`~delayedarray.UnaryIsometricOpWithArgs.UnaryIsometricOpWithArgs`;
or a ``DelayedArray`` of the same dimensions as :py:attr:`~shape`.
Returns:
A ``DelayedArray`` containing the delayed AND operation.
"""
return _wrap_isometric_with_args(self, other, operation="logical_or", right=True)

def __rand__(self, other) -> "DelayedArray":
"""Element-wise AND with the right-hand-side of a ``DelayedArray``.
Args:
other:
A numeric scalar;
or a NumPy array with dimensions as described in
:py:class:`~delayedarray.UnaryIsometricOpWithArgs.UnaryIsometricOpWithArgs`;
or a ``DelayedArray`` of the same dimensions as :py:attr:`~shape`.
Returns:
A ``DelayedArray`` containing the delayed AND operation.
"""
return _wrap_isometric_with_args(self, other, operation="logical_and", right=False)

# Subsetting.
def __getitem__(self, subset: Tuple[Union[slice, Sequence], ...]) -> Union["DelayedArray", ndarray]:
"""Take a subset of this ``DelayedArray``. This follows the same logic as NumPy slicing and will generate a
Expand Down

0 comments on commit 268d8dc

Please sign in to comment.