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 want to repeatedly solve linear systems with a matrix that might be Diagonal. It seems that right now, LinearSolve.jl is not picking an optimal algorithm, or am I missing something? See benchmarks below. The results are similar for different sizes.
Thanks!
using LinearSolve, LinearAlgebra, Random, BenchmarkTools
functionbench_diag(N)
A1 =Diagonal(rand(N))
A2 =copy(A1)
b1 =rand(N)
b2 =copy(b1)
x =similar(b1)
println("\nNaive:")
@btime x =$A2\$b2
x = A2\b2
println(x[1])
println("\npre-allocated:")
@btime$x .=$A2.diag.\$b2
println(x[1])
println("\nLinearSolve1:")
sol =@btimebegin
prob =LinearProblem($A2, $b2)
cache1 =init(prob)
solve(cache1)
endprintln(sol.u[1])
prob =LinearProblem(A1, b1)
cache1 =init(prob)
sol =solve(cache1)
println("\nLinearSolve2:")
sol =@btimebegin
cache2 = LinearSolve.set_b($cache1, $b2)
cache2 = LinearSolve.set_A(cache2, $A2)
solve(cache2)
endprintln(sol.u[1])
endbench_diag(100)
I want to repeatedly solve linear systems with a matrix that might be Diagonal. It seems that right now,
LinearSolve.jl
is not picking an optimal algorithm, or am I missing something? See benchmarks below. The results are similar for different sizes.Thanks!
which prints
The text was updated successfully, but these errors were encountered: