pub fn broadcast_elementwise<F>(
a: &TensorView<'_>,
b: &TensorView<'_>,
out: &mut TensorViewMut<'_>,
op: F,
) -> Result<(), String>Expand description
Element-wise binary operation on two broadcast-compatible views into an output.
This is the core primitive for all binary tensor operators (+, -, *, /). Broadcasting is handled via the stride-zero convention: a dimension with size 1 has stride 0, so the same element is reused without copying.
§Safety
To prevent undefined behavior, the caller must ensure that the output buffer window
does not overlap with the backing storage buffers of a and b unless an exact
in-place operation is intended and safe.
§Errors
Returns Err(String) if the shapes are not broadcast-compatible or the
output buffer is too small for the broadcast output shape.