Skip to content

Commit de0b093

Browse files
Merge pull request #68 from SciML/prec2
More preconditioner cleanup
2 parents 6a67e3b + 02ef42d commit de0b093

File tree

4 files changed

+6
-32
lines changed

4 files changed

+6
-32
lines changed

docs/src/basics/Preconditioners.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,4 @@ following interface:
7272
### General
7373

7474
- `Base.eltype(::Preconditioner)`
75-
- `Base.adjoint(::Preconditioner)`
7675
- `LinearAlgebra.ldiv!(::AbstractVector,::Preconditioner,::AbstractVector)`

src/iterative_wrappers.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
102102
M = cache.Pl
103103
N = cache.Pr
104104

105-
M = (M === Identity()) ? I : inv(M)
106-
N = (N === Identity()) ? I : inv(N)
105+
M = (M === Identity()) ? I : InvPreconditioner(M)
106+
N = (N === Identity()) ? I : InvPreconditioner(N)
107107

108108
atol = cache.abstol
109109
rtol = cache.reltol

src/preconditioners.jl

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ struct InvDiagonalPreconditioner{D}
88
end
99

1010
Base.eltype(A::Union{DiagonalPreconditioner,InvDiagonalPreconditioner}) = eltype(A.diag)
11-
Base.adjoint(A::Union{DiagonalPreconditioner,InvDiagonalPreconditioner}) = A
12-
Base.inv(A::DiagonalPreconditioner) = InvDiagonalPreconditioner(A.diag)
13-
Base.inv(A::InvDiagonalPreconditioner) = DiagonalPreconditioner(A.diag)
1411

1512
function LinearAlgebra.ldiv!(A::DiagonalPreconditioner, x)
1613
x .= x ./ A.diag
@@ -61,8 +58,6 @@ struct ComposePreconditioner{Ti,To}
6158
end
6259

6360
Base.eltype(A::ComposePreconditioner) = promote_type(eltype(A.inner), eltype(A.outer))
64-
Base.adjoint(A::ComposePreconditioner) = ComposePreconditioner(A.outer', A.inner')
65-
Base.inv(A::ComposePreconditioner) = InvComposePreconditioner(A)
6661

6762
function LinearAlgebra.ldiv!(A::ComposePreconditioner, x)
6863
@unpack inner, outer = A
@@ -78,20 +73,9 @@ function LinearAlgebra.ldiv!(y, A::ComposePreconditioner, x)
7873
ldiv!(outer, y)
7974
end
8075

81-
# This is just an implementation detail for Krylov.jl
82-
# It wants to use mul! instead of ldiv! so we convert.
83-
84-
struct InvComposePreconditioner{Tp <: ComposePreconditioner}
85-
P::Tp
76+
struct InvPreconditioner{T}
77+
P::T
8678
end
8779

88-
InvComposePreconditioner(inner, outer) = InvComposePreconditioner(ComposePreconditioner(inner, outer))
89-
90-
Base.eltype(A::InvComposePreconditioner) = Base.eltype(A.P)
91-
Base.adjoint(A::InvComposePreconditioner) = InvComposePreconditioner(A.P')
92-
Base.inv(A::InvComposePreconditioner) = deepcopy(A.P)
93-
94-
function LinearAlgebra.mul!(y, A::InvComposePreconditioner, x)
95-
@unpack P = A
96-
ldiv!(y, P, x)
97-
end
80+
Base.eltype(A::InvPreconditioner) = Base.eltype(A.P)
81+
LinearAlgebra.mul!(y, A::InvPreconditioner, x) = ldiv!(y, A.P, x)

test/runtests.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,20 +243,11 @@ end
243243
P2 = LinearSolve.DiagonalPreconditioner(s2)
244244

245245
P = LinearSolve.ComposePreconditioner(P1,P2)
246-
Pi = LinearSolve.InvComposePreconditioner(P)
247-
248-
@test Pi == LinearSolve.InvComposePreconditioner(P1, P2)
249-
@test Pi == inv(P)
250-
@test P == inv(Pi)
251-
@test Pi' == inv(P')
252246

253247
# ComposePreconditioner
254248
ldiv!(y, P, x); @test y ldiv!(P2, ldiv!(P1, x))
255249
y .= x; ldiv!(P, x); @test x ldiv!(P2, ldiv!(P1, y))
256250

257-
# InvComposePreconditioner
258-
mul!(y, Pi, x); @test y ldiv!(P2, ldiv!(P1, x))
259-
260251
end
261252
end
262253

0 commit comments

Comments
 (0)