Skip to content

Commit 6a27901

Browse files
fix scaling preconditioners
1 parent 8eb92a0 commit 6a27901

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/wrappers.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
## Preconditioners
33

4-
scaling_preconditioner(s) = I * s , I * (1/s)
4+
scaling_preconditioner(s::Number) = I * (1/s), I * s
5+
scaling_preconditioner(s::AbstractVector) = Diagonal(inv.(s)),Diagonal(s)
56

67
struct ComposePreconditioner{Ti,To}
78
inner::Ti

test/runtests.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959
y = solve(_prob)
6060
@test A1 * y b1
6161

62-
62+
6363
_prob = LinearProblem(sparse(A1.A), b1; u0=x1)
6464
y = solve(_prob)
6565
@test A1 * y b1
@@ -215,7 +215,20 @@ end
215215

216216
ldiv!(y, Pl, x); @test y s \ x
217217
ldiv!(y, Pr, x); @test y s * x
218+
end
219+
220+
@testset "vector scaling_preconditioner" begin
221+
s = rand(n)
222+
Pl, Pr = LinearSolve.scaling_preconditioner(s)
223+
224+
mul!(y, Pl, x); @test y s * x
225+
mul!(y, Pr, x); @test y s \ x
226+
227+
y .= x; ldiv!(Pl, x); @test x s \ y
228+
y .= x; ldiv!(Pr, x); @test x s * y
218229

230+
ldiv!(y, Pl, x); @test y s \ x
231+
ldiv!(y, Pr, x); @test y s * x
219232
end
220233

221234
@testset "ComposePreconditioenr" begin

0 commit comments

Comments
 (0)