You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a bit confused why generic_matvecmul! doesn't use @inbounds for the forlloops, as it makes it 5x faster:
julia>import LinearAlgebra: lapack_size
julia>functiongeneric_matvecmul!(C::AbstractVector{R}, tA, A::AbstractVecOrMat, B::AbstractVector) where R
mB =length(B)
mA, nA =lapack_size(tA, A)
if mB != nA
throw(DimensionMismatch("matrix A has dimensions ($mA,$nA), vector B has length $mB"))
endif mA !=length(C)
throw(DimensionMismatch("result C has length $(length(C)), needs length $mA"))
end
Astride =size(A, 1)
if tA =='T'# fastest casefor k =1:mA
aoffs = (k-1)*Astride
if mB ==0
s =zero(R)
else
s =zero(A[aoffs +1]*B[1] + A[aoffs +1]*B[1])
endfor i =1:nA
s +=transpose(A[aoffs+i]) * B[i]
end
C[k] = s
endelseif tA =='C'for k =1:mA
aoffs = (k-1)*Astride
if mB ==0
s =zero(R)
else
s =zero(A[aoffs +1]*B[1] + A[aoffs +1]*B[1])
endfor i =1:nA
s += A[aoffs + i]'B[i]
end
C[k] = s
endelse# tA == 'N'@inboundsfor i =1:mA
if mB ==0
C[i] =zero(R)
else
C[i] =zero(A[i]*B[1] + A[i]*B[1])
endend@inboundsfor k =1:mB
aoffs = (k-1)*Astride
b = B[k]
for i =1:mA
C[i] += A[aoffs + i] * b
endendend
C
end
generic_matvecmul! (generic function with 1 method)
julia> n =1000; A =randn(n,n); x =randn(n); y =randn(n);
julia>@timegeneric_matvecmul!(y, 'N', A, x);
0.000530 seconds (4 allocations:160 bytes)
julia>@time LinearAlgebra.generic_matvecmul!(y, 'N', A, x);
0.001840 seconds (4 allocations:160 bytes)
The text was updated successfully, but these errors were encountered:
I'm a bit confused why generic_matvecmul! doesn't use
@inbounds
for the forlloops, as it makes it 5x faster:The text was updated successfully, but these errors were encountered: