add new Index type
@@ -68,8 +68,24 @@ class DimIndex:
assert self.index < self.sequence_len
-FilePatternIndex = Tuple[DimIndex, ...]
+class Index(tuple):
+ def __new__(self, *args):
+ if not all((isinstance(a, DimIndex) for a in args)):
+ raise ValueError("All arguments must be DimIndex.")
+ args_set = set(args)
+ if len(set(args_set)) < len(args):
+ raise ValueError("Duplicate argument detected.")
+ return tuple.__new__(Index, args)
+
+ def __str__(self):
+ return ",".join(str(dim) for dim in self)
+
+ def __eq__(self, other):
+ return set(self) == set(other)
+
+
CombineDim = Union[MergeDim, ConcatDim]
+FilePatternIndex = Index
class FilePattern:
@@ -154,10 +170,12 @@ class FilePattern:
def __iter__(self) -> Iterator[FilePatternIndex]:
"""Iterate over all keys in the pattern. """
for val in product(*[range(n) for n in self.shape]):
- yield tuple(
+ yield Index(
+ *(
DimIndex(op.name, v, len(op.keys), op.operation)
for op, v in zip(self.combine_dims, val)
)
+ )
def items(self):
"""Iterate over key, filename pairs."""
