diff --git a/micro_ga/multivector.py b/micro_ga/multivector.py index 3c0e7fc..c8af2ad 100644 --- a/micro_ga/multivector.py +++ b/micro_ga/multivector.py @@ -95,6 +95,19 @@ def _add_blades(self, dtype: type|None) -> None: if idx == self.gaDims - 1: setattr(self, 'I', blade_mvec) + def __repr__(self) -> str: + """String representation""" + dtype_str = self.scalar.subtype.__name__ + return f'{type(self).__name__}(sig={self.sig.tolist()}, dtype={dtype_str})' + + def __eq__(self, other) -> bool: + """Algebra comparison""" + if self is other: # The algebra-objects are often identical + return True + if not isinstance(other, type(self)): + return False + return np.array_equal(self.sig, other.sig) + class MVector: """Multi-vector representation""" layout: Cl @@ -105,6 +118,16 @@ def __init__(self, layout: Cl, value: npt.NDArray) -> None: self.layout = layout self.value = value.copy() + @property + def subtype(self) -> type: + """Type of underlying objects""" + # Start with native `numpy` data-type + subtype = self.value.dtype.type + if subtype == np.object_: + # Type of underlying object + subtype = type(self.value.item(0)) + return subtype + def _to_string(self, *, tol: float=0, ndigits: int|None=None) -> str: """String representation, strips near-zero blades""" vals = self.value @@ -144,10 +167,7 @@ def _get_other_value(self, other: OtherArg) -> npt.NDArray: return self.layout.scalar.value * other if not isinstance(other, MVector): return NotImplemented - if self.layout is other.layout: - return other.value # The layout is identical - # Check signature - if not (self.layout.sig == other.layout.sig).all(): + if self.layout != other.layout: return NotImplemented return other.value diff --git a/tests/test_creation.py b/tests/test_creation.py index fc6db75..d4063e4 100644 --- a/tests/test_creation.py +++ b/tests/test_creation.py @@ -23,6 +23,13 @@ def test_dimensions(pos_sig, neg_sig, zero_sig): assert layout.gaDims == 1<