Skip to content

Fix integer overflow in generic matrix-vector multiplication#1659

Open
maleadt wants to merge 1 commit into
masterfrom
tb/gemv
Open

Fix integer overflow in generic matrix-vector multiplication#1659
maleadt wants to merge 1 commit into
masterfrom
tb/gemv

Conversation

@maleadt

@maleadt maleadt commented Jun 24, 2026

Copy link
Copy Markdown
Member

The inner loop formed each product in the narrow input eltype before widening, so narrow-integer inputs overflowed. Form products in the accumulator type via muladd, as already done for matrix-matrix:

LinearAlgebra.jl/src/matmul.jl

Lines 1216 to 1220 in 27b0f13

z2 = zero(A[i, a1]*B[b1, j] + A[i, a1]*B[b1, j])
Ctmp = convert(promote_type(eltype(C), typeof(z2)), z2)
@simd for k in intersect(nzcols(A, i), nzrows(B, j))
Ctmp = muladd(A[i, k], B[k, j], Ctmp)
end

The inner loop formed each product in the narrow input eltype before
widening, so narrow-integer inputs overflowed. Form products in the
accumulator type via muladd, as already done for matrix-matrix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants