MCPcopy Create free account
hub / github.com/dask/dask / broadcast_shapes

Function broadcast_shapes

dask/array/core.py:5054–5086  ·  view source on GitHub ↗

Determines output shape from broadcasting arrays. Parameters ---------- shapes : tuples The shapes of the arguments. Returns ------- output_shape : tuple Raises ------ ValueError If the input shapes cannot be successfully broadcast together

(*shapes)

Source from the content-addressed store, hash-verified

5052
5053
5054def broadcast_shapes(*shapes):
5055 """
5056 Determines output shape from broadcasting arrays.
5057
5058 Parameters
5059 ----------
5060 shapes : tuples
5061 The shapes of the arguments.
5062
5063 Returns
5064 -------
5065 output_shape : tuple
5066
5067 Raises
5068 ------
5069 ValueError
5070 If the input shapes cannot be successfully broadcast together.
5071 """
5072 if len(shapes) == 1:
5073 return shapes[0]
5074 out = []
5075 for sizes in zip_longest(*map(reversed, shapes), fillvalue=-1):
5076 if np.isnan(sizes).any():
5077 dim = np.nan
5078 else:
5079 dim = 0 if 0 in sizes else np.max(sizes).item()
5080 if any(i not in [-1, 0, 1, dim] and not np.isnan(i) for i in sizes):
5081 raise ValueError(
5082 "operands could not be broadcast together with "
5083 "shapes {}".format(" ".join(map(str, shapes)))
5084 )
5085 out.append(dim)
5086 return tuple(reversed(out))
5087
5088
5089def elemwise(op, *args, out=None, where=True, dtype=None, name=None, **kwargs):

Callers 7

_wrap_funcFunction · 0.90
whereFunction · 0.90
test_broadcast_shapesFunction · 0.90
chunksMethod · 0.90
out_indMethod · 0.90
elemwiseFunction · 0.85
broadcast_arraysFunction · 0.85

Calls 4

anyFunction · 0.90
anyMethod · 0.45
maxMethod · 0.45
joinMethod · 0.45

Tested by 1

test_broadcast_shapesFunction · 0.72