Broadcasting

The dot syntax applies any function element-wise, fusing operations into a single loop without temporaries.

The dot syntax applies any function element-wise, fusing operations into a single loop without temporaries.

Broadcast fusion: sqrt.(abs.(x) .+ 1) compiles to one loop.

x = [1.0, 2.0, 3.0]
sin.(x)                       # element-wise
x .+ 1, x .* 2, x .^ 2
x .== 2.0, x .> 1
f(a) = a^2 + 1
f.(x)                         # broadcast any function
@. y = 2x^2 + 3x + 1          # @. adds dots to every operation
y = similar(x); y .= x .* 2   # in-place, no allocation
[1, 2, 3] .+ [10 20]          # broadcasting across dimensions → 3×2 matrix
max.(x, 2.0)
broadcast(+, x, 1)
string.("item", 1:3)          # ["item1", "item2", "item3"]
Ref([1, 2]) .∈ ([1], [3])     # Ref treats an object as a scalar in broadcasting