-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial infrasctructure for preconditioners
- Loading branch information
Showing
4 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
struct JacobiPreconditioner{T, Tv} <: AbstractPreconditioner{T} | ||
d::Tv | ||
|
||
JacobiPreconditioner(d::Tv) where{T, Tv<:AbstractVector{T}} = new{T, Tv}(d) | ||
end | ||
|
||
op(P::JacobiPreconditioner) = Diagonal(P.d) | ||
|
||
# Code for Jacobi preconditioners | ||
function update_preconditioner(kkt::KrylovSPDSolver{T, F, Tv, Ta, Tp}) where{T, F, Tv, Ta<:SparseMatrixCSC, Tp<:JacobiPreconditioner{T, Tv}} | ||
|
||
A = kkt.A | ||
d = kkt.P.d | ||
|
||
# S = A (Θ⁻¹ + Rp)⁻¹ A' + Rd, so its diagonal writes | ||
# S[i, i] = Σ_j=1..n D[j, j] * A[i, j] ^2, | ||
# where D = (Θ⁻¹ + Rp)⁻¹ | ||
|
||
_d = one(T) ./ (kkt.θ .+ kkt.regP) | ||
|
||
rows = rowvals(A) | ||
vals = nonzeros(A) | ||
m, n = size(A) | ||
|
||
d .= zero(T) | ||
|
||
for j = 1:n | ||
_a = zero(T) | ||
dj = _d[j] | ||
for i in nzrange(A, j) | ||
row = rows[i] | ||
a_ij = vals[i] | ||
|
||
d[row] += dj * a_ij ^2 | ||
end | ||
end | ||
|
||
# I think putting this afterwards is more numerics-friendly | ||
d .+= kkt.regD | ||
|
||
# Invert | ||
d .\= one(T) | ||
|
||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
abstract type AbstractPreconditioner{T} end | ||
|
||
update_preconditioner(::AbstractKKTSolver) = nothing | ||
|
||
struct IdentityPreconditioner end | ||
|
||
op(::IdentityPreconditioner) = LO.opEye() | ||
|
||
include("jacobi.jl") |