Skip to content
fn

broadcast_to_op

→TensorImplPtr
int broadcast_to_op(const int & a, const int & shape)

Python wrappers

Public Python APIs implemented by this engine symbol.

Broadcast a tensor to a larger shape following NumPy rules.

The input shape is right-aligned with shape; size-1 dimensions are replicated and newly prepended axes are inserted. If a is not contiguous a copy is made before the broadcast operation runs.

See Also

expand_op (alias), BroadcastBackward.

Parameters

aTensorImplPtr
Input tensor.
shapeShape
Target shape. Must be NumPy-broadcast-compatible with a.shape.

Returns

TensorImplPtr

A tensor of shape shape whose values are replicated from a.

Raises

ShapeMismatch
If a.shape cannot be broadcast to shape (any mismatching axis where neither side is 1).

Examples

``broadcast_to_op([1, 2, 3], (4, 3))`` produces a 4x3 tensor where every
row equals ``[1, 2, 3]``.