-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Poor performance of mul! with scalar #33105
Comments
Looks like the splatting in Might be good old #29114 again.
|
Looks like so. Using julia> using LinearAlgebra: MulAddMul, _modify!
julia> function mymul!(C::AbstractArray, X::AbstractArray, s::Number, _add::MulAddMul)
if length(C) != length(X)
throw(DimensionMismatch("first array has length $(length(C)) which does not match the length of the second, $(length(X))."))
end
for (IC, IX) in zip(eachindex(C), eachindex(X))
@inbounds _modify!(_add, X[IX] * s, C, (IC,))
end
C
end
mymul! (generic function with 1 method)
julia> @btime mymul!($y, $x, $λ, $(LinearAlgebra.MulAddMul(true, false)));
9.512 ns (0 allocations: 0 bytes)
julia> @btime LinearAlgebra.generic_mul!($y, $λ, $x, $(LinearAlgebra.MulAddMul(true, false)));
938.111 ns (30 allocations: 640 bytes)
julia> @btime $y .= $λ .* $x;
7.661 ns (0 allocations: 0 bytes) |
Can |
Why is the splatting in To reproduce: using LinearAlgebra
A = randn(ComplexF64, (10,10))
B = SymTridiagonal(randn(10), randn(9))
mul!(A, B, 0.5) # works
mul!(view(A,1:10,1:10), B, 0.5) yields
|
@Jutho See #33187 for a fix I suggest.
There are many functions passing a tuple of ints to julia/stdlib/LinearAlgebra/src/triangular.jl Lines 480 to 490 in cb76f2a
|
On
I see
In contrast, the hand-written
as expected. Interestingly, on Julia v1.2 I get
so it seems like broadcasting has significantly improved, and something is simply going wrong with
mul!
.The text was updated successfully, but these errors were encountered: