Skip to content

fix scaling preconditioners #45

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

Merged
merged 3 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/pardiso.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@

## Pardiso

import Pardiso

export PardisoJL, MKLPardisoFactorize, MKLPardisoIterate

Base.@kwdef struct PardisoJL <: SciMLLinearSolveAlgorithm
nprocs::Union{Int, Nothing} = nothing
solver_type::Union{Int, Pardiso.Solver, Nothing} = nothing
Expand Down Expand Up @@ -93,3 +86,5 @@ function SciMLBase.solve(cache::LinearCache, alg::PardisoJL; kwargs...)

return SciMLBase.build_linear_solution(alg,cache.u,nothing)
end

export PardisoJL, MKLPardisoFactorize, MKLPardisoIterate
3 changes: 2 additions & 1 deletion src/wrappers.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

## Preconditioners

scaling_preconditioner(s) = I * s , I * (1/s)
scaling_preconditioner(s::Number) = I * (1/s), I * s
scaling_preconditioner(s::AbstractVector) = Diagonal(inv.(s)),Diagonal(s)

struct ComposePreconditioner{Ti,To}
inner::Ti
Expand Down
20 changes: 18 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end
y = solve(_prob)
@test A1 * y ≈ b1


_prob = LinearProblem(sparse(A1.A), b1; u0=x1)
y = solve(_prob)
@test A1 * y ≈ b1
Expand Down Expand Up @@ -205,7 +205,7 @@ end
x = rand(n,n)
y = rand(n,n)

Pl, Pr = LinearSolve.scaling_preconditioner(s)
Pl, Pr = LinearSolve.scaling_preconditioner(1/s)

mul!(y, Pl, x); @test y ≈ s * x
mul!(y, Pr, x); @test y ≈ s \ x
Expand All @@ -215,7 +215,23 @@ end

ldiv!(y, Pl, x); @test y ≈ s \ x
ldiv!(y, Pr, x); @test y ≈ s * x
end

@testset "vector scaling_preconditioner" begin
s = rand(n)
Pl, Pr = LinearSolve.scaling_preconditioner(1 ./ s)

x = rand(n,n)
y = rand(n,n)

mul!(y, Pl, x); @test y ≈ s .* x
mul!(y, Pr, x); @test y ≈ s .\ x

y .= x; ldiv!(Pl, x); @test x ≈ s .\ y
y .= x; ldiv!(Pr, x); @test x ≈ s .* y

ldiv!(y, Pl, x); @test y ≈ s .\ x
ldiv!(y, Pr, x); @test y ≈ s .* x
end

@testset "ComposePreconditioenr" begin
Expand Down