Implementing kernel
C++ engine symbols that back this Python API.Broadcast a tensor to a target shape.
Performs the standard right-aligned broadcasting rules: dimensions of
size 1 in the input may be expanded to any size in shape; new
leading dimensions may be prepended. On the CPU the result is a view of
input's buffer, as expand's is; on metal it is a copy.
Parameters
inputTensorSource tensor.
shapeShapeLikeTarget shape. Must be broadcast-compatible with
input.shape.Returns
Tensorinput under the requested shape — a read-only view on the CPU,
a copy on metal.
Notes
On the CPU the broadcast axes have stride 0, so every repeated element is
one of input's and a write through the result is refused; call
contiguous() on it first for a writable copy.
Examples
>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> lucid.broadcast_to(x, (2, 3))
Tensor([[1., 2., 3.],
[1., 2., 3.]])