-def _iter2(obj1, obj2):
- if obj1.symbols != obj2.symbols:
- raise ValueError('arguments must belong to the same space')
- coordinates1 = obj1._coordinates.values()
- coordinates2 = obj2._coordinates.values()
- yield from zip(obj1.symbols, coordinates1, coordinates2)
+ __slots__ = (
+ '_coordinates',
+ )
+
+ @abstractmethod
+ def __new__(cls):
+ super().__new__(cls)
+
+ @property
+ def symbols(self):
+ return tuple(self._coordinates)
+
+ @property
+ def dimension(self):
+ return len(self.symbols)
+
+ def coordinates(self):
+ yield from self._coordinates.items()
+
+ def coordinate(self, symbol):
+ if not isinstance(symbol, Symbol):
+ raise TypeError('symbol must be a Symbol instance')
+ return self._coordinates[symbol]
+
+ __getitem__ = coordinate
+
+ def __bool__(self):
+ return any(self._coordinates.values())
+
+ def __hash__(self):
+ return hash(tuple(self.coordinates()))
+
+ def __repr__(self):
+ string = ', '.join(['{!r}: {!r}'.format(symbol, coordinate)
+ for symbol, coordinate in self.coordinates()])
+ return '{}({{{}}})'.format(self.__class__.__name__, string)