Skip to content

Commit 27a7d88

Browse files
committed
InvComposePreconditioner done
1 parent 1793e51 commit 27a7d88

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

src/wrappers.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ end
5050

5151
InvComposePreconditioner(inner, outer) = InvComposePreconditioner(ComposePreconditioner(inner, outer))
5252

53-
Base.eltype(A::InvComposePreconditioner) = Float64 #eltype(A.inner)
54-
#Base.adjoint(A::InvComposePreconditioner) = ComposePreconditioner(A.outer', A.inner')
55-
Base.inv(A::InvComposePreconditioner) = ComposePreconditioner(A.P)
53+
Base.eltype(A::InvComposePreconditioner) = Base.eltype(A.P)
54+
Base.adjoint(A::InvComposePreconditioner) = InvComposePreconditioner(A.P')
55+
Base.inv(A::InvComposePreconditioner) = deepcopy(A.P)
5656

5757
function LinearAlgebra.mul!(y, A::InvComposePreconditioner, x)
5858
@unpack P = A
@@ -61,10 +61,15 @@ end
6161

6262
function LinearAlgebra.mul!(C, A::InvComposePreconditioner, B, α, β)
6363
@unpack P = A
64+
tmp = copy(B)
65+
ldiv!(tmp, P, B)
66+
mul!(C, I, tmp, α, β)
6467
end
6568

6669
function LinearAlgebra.ldiv!(A::InvComposePreconditioner, x)
6770
@unpack P = A
71+
y = copy(x)
72+
mul!(x, P, y)
6873
end
6974

7075
function LinearAlgebra.ldiv!(y, A::InvComposePreconditioner, x)
@@ -175,15 +180,8 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
175180
cache = set_cacheval(cache, solver)
176181
end
177182

178-
M = alg.Pl
179-
N = alg.Pr
180-
181-
"""
182-
TODO - pass in inv(Pl), inv(Pr) to Krylov.jl
183-
"""
184-
185-
# M = InvComposePreconditioner(alg.Pl, cache.Pl) # left precond
186-
# N = InvComposePreconditioner(alg.Pr, cache.Pr) # right
183+
M = InvComposePreconditioner(alg.Pl, cache.Pl) # left precond
184+
N = InvComposePreconditioner(alg.Pr, cache.Pr) # right
187185

188186
atol = cache.abstol
189187
rtol = cache.reltol

test/runtests.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,38 @@ end
172172
ldiv!(y, P, x)
173173

174174
end
175+
176+
@testset "InvComposePreconditioenr" begin
177+
s = rand()
178+
α = rand()
179+
β = rand()
180+
181+
x = rand(n,n)
182+
y = rand(n,n)
183+
184+
P1 = LinearSolve.default_preconditioner(s, true)
185+
P2 = LinearSolve.default_preconditioner(s, false)
186+
187+
P = LinearSolve.ComposePreconditioner(P1,P2)
188+
Pi = LinearSolve.InvComposePreconditioner(P)
189+
190+
@test Pi == LinearSolve.InvComposePreconditioner(P1,P2)
191+
@test Pi == inv(P)
192+
@test P == inv(Pi)
193+
194+
mul!(y, P, x)
195+
mul!(y, P, x, α, β)
196+
197+
ldiv!(P, x)
198+
ldiv!(y, P, x)
199+
200+
mul!(y, Pi, x)
201+
mul!(y, Pi, x, α, β)
202+
203+
ldiv!(Pi, x)
204+
ldiv!(y, Pi, x)
205+
206+
end
175207
end
176208

177209
end # testset

0 commit comments

Comments
 (0)