Skip to content

Commit

Permalink
Arithmetic operations return NotImplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
trundev committed Dec 25, 2024
1 parent d72aafe commit d7a7039
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions micro_ga/multivector.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,27 @@ def _get_other_value(self, other: OtherArg) -> npt.NDArray:
# Check if it is scalar
if isinstance(other, numbers.Number):
return self.layout.scalar.value * other

assert isinstance(other, MVector), 'Must be MVector or Number'
if not isinstance(other, MVector):
return NotImplemented
if self.layout is other.layout:
return other.value # The layout is identical
# Check signature
np.testing.assert_array_equal(self.layout.sig, other.layout.sig,
'Multi-vector signatures must match')
if not (self.layout.sig == other.layout.sig).all():
return NotImplemented
return other.value

def __eq__(self, other) -> bool:
"""Comparison"""
value = self._get_other_value(other)
if value is NotImplemented:
return NotImplemented
return (self.value == value).all()

def __add__(self, other: OtherArg) -> 'MVector':
"""Left-side addition"""
value = self._get_other_value(other)
if value is NotImplemented:
return NotImplemented
return MVector(self.layout, self.value + value)

__radd__ = __add__
Expand Down

0 comments on commit d7a7039

Please sign in to comment.