MCPcopy
hub / github.com/pydata/xarray / unified_dim_sizes

Function unified_dim_sizes

xarray/computation/apply_ufunc.py:621–642  ·  view source on GitHub ↗
(
    variables: Iterable[Variable], exclude_dims: AbstractSet = frozenset()
)

Source from the content-addressed store, hash-verified

619
620
621def unified_dim_sizes(
622 variables: Iterable[Variable], exclude_dims: AbstractSet = frozenset()
623) -> dict[Hashable, int]:
624 dim_sizes: dict[Hashable, int] = {}
625
626 for var in variables:
627 if len(set(var.dims)) < len(var.dims):
628 raise ValueError(
629 "broadcasting cannot handle duplicate "
630 f"dimensions on a variable: {list(var.dims)}"
631 )
632 for dim, size in zip(var.dims, var.shape, strict=True):
633 if dim not in exclude_dims:
634 if dim not in dim_sizes:
635 dim_sizes[dim] = size
636 elif dim_sizes[dim] != size:
637 raise ValueError(
638 "operands cannot be broadcast together "
639 "with mismatched lengths for dimension "
640 f"{dim}: {dim_sizes[dim]} vs {size}"
641 )
642 return dim_sizes
643
644
645SLICE_NONE = slice(None)

Callers 2

test_unified_dim_sizesFunction · 0.90
apply_variable_ufuncFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_unified_dim_sizesFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…