Skip to content

Commit 3094afa

Browse files
committed
try fix using pdata with shifts for least-squares (segfault locally)
1 parent 657fdb7 commit 3094afa

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

src/main.jl

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ function preprocess(stp::NLPStopping, PData::TPData, workspace::TRARCWorkspace,
8383
return PData
8484
end
8585

86+
function preprocess(
87+
stp::NLPStopping,
88+
PData::PDataIterLS,
89+
workspace::TRARCWorkspace{T,S,Hess},
90+
∇f,
91+
norm_∇f,
92+
α,
93+
) where {T,S,Hess<:HessGaussNewtonOp}
94+
max_hprod = stp.meta.max_cntrs[:neval_jprod_residual]
95+
Fx = workspace.Fx
96+
Jx = jac_op_residual!(stp.pb, workspace.xt, workspace.Hstruct.Jv, workspace.Hstruct.Jtv)
97+
PData = ARCTR.preprocess(PData, Jx, Fx, norm_∇f, neval_jprod_residual(stp.pb), max_hprod, α)
98+
return PData
99+
end
100+
86101
function compute_direction(
87102
stp::NLPStopping,
88103
PData::TPData,
@@ -132,21 +147,21 @@ function hessian!(workspace::TRARCWorkspace, nlp, x)
132147
end
133148

134149
function TRARC(
135-
nlp_stop::NLPStopping{Pb, M, SRC, NLPAtX{Score, T, S}, MStp, LoS};
136-
TR::TrustRegion = TrustRegion(T(10.0)),
137-
hess_type::Type{Hess} = HessOp,
138-
pdata_type::Type{ParamData} = PDataKARC,
139-
kwargs...,
140-
) where {Pb, M, SRC, MStp, LoS, Score, S, T, Hess, ParamData}
141-
nlp = nlp_stop.pb
142-
143-
if ParamData == PDataNLSST
144-
PData = PDataNLSST(S, T, nlp.meta.nvar, nlp.nls_meta.nequ; kwargs...)
145-
else
146-
PData = ParamData(S, T, nlp.meta.nvar; kwargs...)
147-
end
148-
workspace = TRARCWorkspace(nlp, Hess)
149-
return TRARC(nlp_stop, PData, workspace, TR; kwargs...)
150+
nlp_stop::NLPStopping{Pb,M,SRC,NLPAtX{Score,T,S},MStp,LoS};
151+
TR::TrustRegion = TrustRegion(T(10.0)),
152+
hess_type::Type{Hess} = HessOp,
153+
pdata_type::Type{ParamData} = PDataKARC,
154+
kwargs...,
155+
) where {Pb,M,SRC,MStp,LoS,Score,S,T,Hess,ParamData}
156+
nlp = nlp_stop.pb
157+
158+
if ParamData in (PDataNLSST, PDataLSKARC)
159+
PData = ParamData(S, T, nlp.meta.nvar, nlp.nls_meta.nequ; kwargs...)
160+
else
161+
PData = ParamData(S, T, nlp.meta.nvar; kwargs...)
162+
end
163+
workspace = TRARCWorkspace(nlp, Hess)
164+
return TRARC(nlp_stop, PData, workspace, TR; kwargs...)
150165
end
151166

152167
"""

src/utils/pdata_struct.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ end
119119
PDataLSKARC(::Type{S}, ::Type{T}, n)
120120
Return a structure used for the preprocessing of ARCqK methods.
121121
"""
122-
mutable struct PDataLSKARC{T} <: PDataIter{T}
122+
mutable struct PDataLSKARC{T} <: PDataIterLS{T}
123123
d::Array{T,1} # (H+λI)\g ; on first call = g
124124
λ::T # "active" value of λ; on first call = 0
125125
ζ::T # Inexact Newton order parameter: stop when ||∇q|| < ξ * ||g||^(1+ζ)
@@ -144,7 +144,8 @@ end
144144
function PDataLSKARC(
145145
::Type{S},
146146
::Type{T},
147-
n;
147+
n,
148+
m;
148149
ζ = T(0.5),
149150
ξ = T(0.01),
150151
maxtol = T(0.01),
@@ -167,9 +168,9 @@ function PDataLSKARC(
167168
norm_dirs = S(undef, nshifts)
168169
OK = true
169170
solver = if solver_method == :cgls
170-
CglsLanczosShiftSolver(n, n, nshifts, S)
171+
CglsLanczosShiftSolver(m, n, nshifts, S)
171172
else
172-
LsqrShiftSolver(n, n, nshifts, S)
173+
LsqrShiftSolver(m, n, nshifts, S)
173174
end
174175
return PDataLSKARC(
175176
d,

0 commit comments

Comments
 (0)