LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

Don't zero out destination in generic_matvecmul

Open jishnub opened this issue 8 months ago • 0 comments

Currently, mul!(c::AbstractVector, A::AbstractMatrix, b::AbstractVector) is computed (schematically) as

c .= 0 # zero of the correct type
for y in eachcol(A .* permutedims(b))
    c .+= y
end

Filling c with zeros at the beginning is unnecessary. We may instead start by storing first(eachcol(A .* permutedims(b))) directly in c, followed by a loop over the other columns. This reduces one loop over c, although the difference in performance is minimal.

jishnub avatar Mar 17 '25 12:03 jishnub