Skip to content

Don't zero out destination in generic_matvecmul #1242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Mar 17, 2025

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.

C[i] = false
else
C[i] = zero(A[i]*B[1] + A[i]*B[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see how to get this working, without modifying the corresponding test case, which fails for all commits on this branch. We need this sum here to be able to promote to the eltype of C, but we don't have zero available for neither A nor B. If this doesn't affect performance too much, maybe it's not worth it after all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, probably not worth it

@jishnub jishnub closed this Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants