Skip to content

Commit

Permalink
Fix invert (~) operator for bool
Browse files Browse the repository at this point in the history
  • Loading branch information
holl- committed Nov 24, 2023
1 parent f0f4086 commit 1bf1dea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions phiml/backend/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,11 @@ def shift_bits_right(self, a, b):
a, b = self.auto_cast(a, b)
return a >> b

def invert(self, x):
if isinstance(x, bool):
return not x
return ~x


BACKENDS: List[Backend] = []
""" Global list of all registered backends. Register a `Backend` by adding it to the list. """
Expand Down
2 changes: 1 addition & 1 deletion phiml/math/_tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def __neg__(self):
return self._op1(lambda t: -t)

def __invert__(self):
return self._op1(lambda t: ~t)
return self._op1(lambda t: choose_backend(t).invert(t))

def __reversed__(self):
assert self.shape.channel.rank == 1
Expand Down

0 comments on commit 1bf1dea

Please sign in to comment.