From d7a70392cde3163a76696503471af8eac34c4b79 Mon Sep 17 00:00:00 2001 From: Todor Trundev Date: Mon, 23 Dec 2024 14:28:27 +0200 Subject: [PATCH] Arithmetic operations return NotImplemented See the example here: https://docs.python.org/3/library/numbers.html#implementing-the-arithmetic-operations --- micro_ga/multivector.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/micro_ga/multivector.py b/micro_ga/multivector.py index 75a5318..cf10e1f 100644 --- a/micro_ga/multivector.py +++ b/micro_ga/multivector.py @@ -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__