Skip to content

Commit dca73f4

Browse files
minor fixes in shiftedCompositeNormL2
1 parent b3035c4 commit dca73f4

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/compositeNormL2.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ mutable struct CompositeNormL2{
3535
J!::F1
3636
A::M
3737
b::V
38+
store_previous_jacobian::Bool
3839

3940
function CompositeNormL2(
4041
λ::T,
4142
c!::Function,
4243
J!::Function,
4344
A::AbstractMatrix{T},
44-
b::AbstractVector{T},
45+
b::AbstractVector{T};
46+
store_previous_jacobian::Bool = false
4547
) where {T <: Real}
4648
λ > 0 || error("CompositeNormL2: λ should be positive")
4749
length(b) == size(A, 1) || error(
4850
"Composite Norm L2: Wrong input dimensions, the length of c(x) should be the same as the number of rows of J(x)",
4951
)
50-
new{T, typeof(c!), typeof(J!), typeof(A), typeof(b)}(NormL2(λ), c!, J!, A, b)
52+
new{T, typeof(c!), typeof(J!), typeof(A), typeof(b)}(NormL2(λ), c!, J!, A, b, store_previous_jacobian)
5153
end
5254
end
5355

src/shiftedCompositeNormL2.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ mutable struct ShiftedCompositeNormL2{
3333
c!::F0
3434
J!::F1
3535
A::M
36+
A_prev::Union{Nothing, M} # (Optional) can be used to store the previous Jacobian, useful for quasi-Newton approximations
3637
shifted_spmat::qrm_shifted_spmat{T}
3738
spfct::qrm_spfct{T}
3839
b::V
@@ -41,12 +42,14 @@ mutable struct ShiftedCompositeNormL2{
4142
dq::V # Preallocated vector to refine the q solution.
4243
p::V # Preallocated vector used to compute s(α)ᵀ∇s(α) for the secular equation.
4344
dp::V # Preallocated vector used to refine the p vector.
45+
full_row_rank::Bool # Boolean that tells whether A has full row rank or not. Is updated on each call to `prox!`
4446
function ShiftedCompositeNormL2(
4547
λ::T,
4648
c!::Function,
4749
J!::Function,
4850
A::AbstractMatrix{T},
49-
b::AbstractVector{T},
51+
b::AbstractVector{T};
52+
store_previous_jacobian::Bool = false
5053
) where {T <: Real}
5154
p = similar(b, A.n + A.m)
5255
dp = similar(b, A.n + A.m)
@@ -59,6 +62,8 @@ mutable struct ShiftedCompositeNormL2{
5962
)
6063
end
6164

65+
A_prev = store_previous_jacobian ? copy(A) : nothing
66+
6267
spmat = qrm_spmat_init(A; sym = false)
6368
shifted_spmat = qrm_shift_spmat(spmat)
6469
spfct = qrm_spfct_init(spmat)
@@ -68,6 +73,7 @@ mutable struct ShiftedCompositeNormL2{
6873
c!,
6974
J!,
7075
A,
76+
A_prev,
7177
shifted_spmat,
7278
spfct,
7379
b,
@@ -76,6 +82,7 @@ mutable struct ShiftedCompositeNormL2{
7682
dq,
7783
p,
7884
dp,
85+
false
7986
)
8087
end
8188
end
@@ -94,7 +101,7 @@ shifted(
94101
ψ.c!(b, xk)
95102
A = similar.A)
96103
ψ.J!(A, xk)
97-
ShiftedCompositeNormL2.h.lambda, ψ.c!, ψ.J!, A, b)
104+
ShiftedCompositeNormL2.h.lambda, ψ.c!, ψ.J!, A, b, store_previous_jacobian = ψ.store_previous_jacobian)
98105
end
99106

100107
fun_name::ShiftedCompositeNormL2) = "shifted `ℓ₂` norm"
@@ -110,6 +117,7 @@ function prox!(
110117
atol = eps(T)^0.3,
111118
max_time = 180.0,
112119
) where {T <: Real, F0 <: Function, F1 <: Function, M <: AbstractMatrix{T}, V <: AbstractVector{T}}
120+
@assert ν > zero(T)
113121
start_time = time()
114122
θ = T(0.8)
115123
α = zero(T)
@@ -134,8 +142,8 @@ function prox!(
134142
_obj_dot_grad!(spmat, spfct, ψ.p, ψ.q, ψ.g, ψ.dq)
135143

136144
# Check full-rankness
137-
full_row_rank = (qrm_get(spfct, "qrm_rd_num") == 0)
138-
if !full_row_rank
145+
ψ.full_row_rank = (qrm_get(spfct, "qrm_rd_num") == 0)
146+
if !ψ.full_row_rank
139147
# QRMumps cannot factorize rank-deficient matrices; use the Golub-Riley iteration instead
140148
α = αmin
141149
qrm_golub_riley!(

0 commit comments

Comments
 (0)