Skip to content

Commit

Permalink
Allow kwargs to pass to lldl (#32)
Browse files Browse the repository at this point in the history
* Allows kwargs to pass to lldl

* Remove spurious "where T"

* Add kwargs test

* Bump version and compat
  • Loading branch information
JeffFessler authored Feb 25, 2023
1 parent 0a69dc5 commit c25cf1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Preconditioners"
uuid = "af69fa37-3177-5a40-98ee-561f696e4fcd"
version = "0.5.2"
version = "0.6"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand All @@ -10,7 +10,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
AlgebraicMultigrid = "0.4, 0.5"
LimitedLDLFactorizations = "0.4"
LimitedLDLFactorizations = "0.4, 0.5"
julia = "1.6"

[extras]
Expand Down
18 changes: 14 additions & 4 deletions src/incompletecholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@ function assert_pd(d, α)
@assert α == 0 && all(x -> x > 0, d) "The input matrix is not positive definite."
end

"""
CholeskyPreconditioner(A, memory=2; kwargs...)
Construct
`CholeskyPreconditioner` from matrix `A`
for parameters `memory` and `kwargs` passed to
`LimitedLDLFactorizations.lldl`.
"""
mutable struct CholeskyPreconditioner{L} <: AbstractPreconditioner
ldlt::L
memory::Int
function CholeskyPreconditioner(A, memory=2)
function CholeskyPreconditioner(A, memory=2; kwargs...)
_A = get_data(A)
LLDL = lldl(_A, memory=memory)
LLDL = lldl(_A; memory, kwargs...)
assert_pd(LLDL.D, LLDL.α)
return new{typeof(LLDL)}(LLDL, memory)
end
end

function UpdatePreconditioner!(C::CholeskyPreconditioner, A, memory=C.memory)
"""
UpdatePreconditioner!(C::CholeskyPreconditioner, A, memory=C.memory; kwargs...)
"""
function UpdatePreconditioner!(C::CholeskyPreconditioner, A, memory=C.memory; kwargs...)
_A = get_data(A)
LLDL = lldl(_A, memory=memory)
LLDL = lldl(_A; memory, kwargs...)
assert_pd(LLDL.D, LLDL.α)
C.ldlt = LLDL
return C
Expand Down
15 changes: 12 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using LinearAlgebra, SparseArrays, Preconditioners, IterativeSolvers, Random, Test
using OffsetArrays
using LinearAlgebra: I, diag, ldiv!, norm, Symmetric, Hermitian
using SparseArrays: sprand
using Preconditioners: CholeskyPreconditioner, DiagonalPreconditioner
using Preconditioners: RugeStuben, SmoothedAggregation
using Preconditioners: UpdatePreconditioner!, AMGPreconditioner
using IterativeSolvers: cg
using Random: seed!
using Test: @test, @testset, @test_throws
using OffsetArrays: OffsetMatrix, OffsetVector

Random.seed!(1)
seed!(1)

function test_matrix(A, F, atol)
n = size(A, 1)
Expand All @@ -10,6 +17,8 @@ function test_matrix(A, F, atol)
C = CholeskyPreconditioner(A, n)
@test isapprox(norm(C \ b - Symmetric(A) \ b, Inf), 0.0, atol=atol)
UpdatePreconditioner!(C, A, 2)

C2 = CholeskyPreconditioner(A, n; check_tril = true) # check kwargs
end
if F === RugeStuben || F === SmoothedAggregation
p = AMGPreconditioner(F, A)
Expand Down

5 comments on commit c25cf1b

@t-bltg
Copy link
Contributor

@t-bltg t-bltg commented on c25cf1b Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohamed82008, can you register this version ?

@mohamed82008
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @JuliaRegistrator register

@mohamed82008
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/79261

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" c25cf1bb2c964c56847185b1d854fc2136963f78
git push origin v0.6.0

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/79261

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" c25cf1bb2c964c56847185b1d854fc2136963f78
git push origin v0.6.0

Please sign in to comment.