Extract dimension sizes from a dictionary of variables. Raises ValueError if any dimensions have different sizes.
(variables: list[Variable])
| 83 | |
| 84 | |
| 85 | def broadcast_dimension_size(variables: list[Variable]) -> dict[Hashable, int]: |
| 86 | """Extract dimension sizes from a dictionary of variables. |
| 87 | |
| 88 | Raises ValueError if any dimensions have different sizes. |
| 89 | """ |
| 90 | dims: dict[Hashable, int] = {} |
| 91 | for var in variables: |
| 92 | for dim, size in zip(var.dims, var.shape, strict=True): |
| 93 | if dim in dims and size != dims[dim]: |
| 94 | raise ValueError(f"index {dim!r} not aligned") |
| 95 | dims[dim] = size |
| 96 | return dims |
| 97 | |
| 98 | |
| 99 | class MergeError(ValueError): |
no outgoing calls
no test coverage detected
searching dependent graphs…