oneflow.broadcast_shapes¶
-
oneflow.broadcast_shapes(*shapes) → Size¶ The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.broadcast_shapes.html.
Similar to
oneflow.broadcast_tensors()but for shapes.This is equivalent to
flow.broadcast_tensors(*map(flow.empty, shapes))[0].shapebut avoids the need create to intermediate tensors. This is useful for broadcasting tensors of common batch shape but different rightmost shape, e.g. to broadcast mean vectors with covariance matrices.- Parameters
*shapes (flow.Size) – Shapes of tensors.
- Returns
A shape compatible with all input shapes.
- Raises
RuntimeError – If shapes are incompatible.
Example:
>>> import oneflow as flow >>> flow.broadcast_shapes((2,), (3, 1), (1, 1, 1)) oneflow.Size([1, 3, 2])