[KongchangAI]
ConceptBroadcasting

Broadcasting

A rule in tensor operations that automatically expands tensors of different shapes so that element-wise computation can be performed. Broadcasting allows operations between arrays with compatible but non-identical dimensions by implicitly replicating data along size-one dimensions. Both PyTorch and NumPy support this mechanism, which removes the need for explicit shape replication and reduces memory overhead in numerical computation.

Timeline (last 90 days)

Nov 10

Broadcasting rules: starting from the trailing dimension (rightmost) and comparing dimension by dimension, if the two dimensions are equal or one of them is 1, they are considered compatible; when compatible, the dimension of size 1 is expanded to match the size of the other dimension. If a dimension is neither equal nor 1, an error is thrown.

Unverified50%
Nov 10

Broadcasting does not actually allocate memory to copy data; instead it is implemented via a virtual expansion with a stride of 0, so it is efficient and saves GPU memory.

Unverified50%
Sep 21

Broadcasting aligns dimensions from the trailing end, and dimensions of size 1 can be implicitly expanded to match the other operand without actually copying memory

Unverified50%

All Facts (3)

Source Articles