Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Dec 19, 2021
1 parent 78c3b68 commit 5220f98
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
3 changes: 2 additions & 1 deletion docs/src/basics/Preconditioners.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ To define a new preconditioner you define a Julia type which satisfies the
following interface:

- `Base.eltype(::Preconditioner)` (Required only for Krylov.jl)
- `LinearAlgebra.ldiv!(::AbstractVector,::Preconditioner,::AbstractVector)`
- `LinearAlgebra.ldiv!(::AbstractVector,::Preconditioner,::AbstractVector)` and
`LinearAlgebra.ldiv!(::Preconditioner,::AbstractVector)`

## Curated List of Pre-Defined Preconditioners

Expand Down
2 changes: 2 additions & 0 deletions src/preconditioners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ struct InvPreconditioner{T}
end

Base.eltype(A::InvPreconditioner) = Base.eltype(A.P)
LinearAlgebra.ldiv!(A::InvPreconditioner, x) = mul!(x, A.P, x)
LinearAlgebra.ldiv!(y, A::InvPreconditioner, x) = mul!(y, A.P, x)
LinearAlgebra.mul!(y, A::InvPreconditioner, x) = ldiv!(y, A.P, x)
29 changes: 5 additions & 24 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,9 @@ end
end

@testset "Preconditioners" begin
@testset "Scalar Diagonal Preconditioner" begin
s = rand()

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

Pl, Pr = LinearSolve.DiagonalPreconditioner(s),LinearSolve.InvDiagonalPreconditioner(s)

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 "Vector Diagonal Preconditioner" begin
s = rand(n)
Pl, Pr = LinearSolve.DiagonalPreconditioner(s),LinearSolve.InvDiagonalPreconditioner(s)
Pl, Pr = Diagonal(s),LinearSolve.InvPreconditioner(Diagonal(s))

x = rand(n,n)
y = rand(n,n)
Expand All @@ -237,21 +219,20 @@ end
end

@testset "ComposePreconditioenr" begin
s1 = rand()
s2 = rand()
s1 = rand(n)
s2 = rand(n)

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

P1 = LinearSolve.DiagonalPreconditioner(s1)
P2 = LinearSolve.DiagonalPreconditioner(s2)
P1 = Diagonal(s1)
P2 = Diagonal(s2)

P = LinearSolve.ComposePreconditioner(P1,P2)

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

end
end

Expand Down

0 comments on commit 5220f98

Please sign in to comment.