Resolves a supplied list containing an ellipsis representing other items, to a generator with the 'realized' list of all items
(
dims_supplied: Iterable[_Dim],
dims_all: Iterable[_Dim],
missing_dims: ErrorOptionsWithWarn = "raise",
)
| 151 | |
| 152 | |
| 153 | def infix_dims( |
| 154 | dims_supplied: Iterable[_Dim], |
| 155 | dims_all: Iterable[_Dim], |
| 156 | missing_dims: ErrorOptionsWithWarn = "raise", |
| 157 | ) -> Iterator[_Dim]: |
| 158 | """ |
| 159 | Resolves a supplied list containing an ellipsis representing other items, to |
| 160 | a generator with the 'realized' list of all items |
| 161 | """ |
| 162 | if ... in dims_supplied: |
| 163 | dims_all_list = list(dims_all) |
| 164 | if len(set(dims_all)) != len(dims_all_list): |
| 165 | raise ValueError("Cannot use ellipsis with repeated dims") |
| 166 | if list(dims_supplied).count(...) > 1: |
| 167 | raise ValueError("More than one ellipsis supplied") |
| 168 | other_dims = [d for d in dims_all if d not in dims_supplied] |
| 169 | existing_dims = drop_missing_dims(dims_supplied, dims_all, missing_dims) |
| 170 | for d in existing_dims: |
| 171 | if d is ...: |
| 172 | yield from other_dims |
| 173 | else: |
| 174 | yield d |
| 175 | else: |
| 176 | existing_dims = drop_missing_dims(dims_supplied, dims_all, missing_dims) |
| 177 | if set(existing_dims) ^ set(dims_all): |
| 178 | raise ValueError( |
| 179 | f"{dims_supplied} must be a permuted list of {dims_all}, unless `...` is included" |
| 180 | ) |
| 181 | yield from existing_dims |
| 182 | |
| 183 | |
| 184 | def either_dict_or_kwargs( |
searching dependent graphs…