Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/NLsolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ include("nlsolve/nlsolve.jl")
include("nlsolve/utils.jl")
include("nlsolve/fixedpoint.jl")

include("trace_tools.jl")

end # module
16 changes: 16 additions & 0 deletions src/trace_tools.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trace(r::SolverResults) = r.trace
function x_trace(r::SolverResults)
tr = trace(r).states
!haskey(tr[1].metadata, "x") && error("Trace does not contain x. To get a trace of x, run nlsolve() with extended_trace = true")
[ state.metadata["x"] for state in tr ]
end
function F_trace(r::SolverResults)
tr = trace(r).states
!haskey(tr[1].metadata, "f(x)") && error("Trace does not contain F. To get a trace of the residuals, run nlsolve() with extended_trace = true")
[ state.metadata["f(x)"] for state in tr ]
end
function J_trace(r::SolverResults)
tr = trace(r).states
!haskey(tr[1].metadata, "g(x)") && error("Trace does not contain J. To get a trace of the Jacobian, run nlsolve() with extended_trace = true")
[ state.metadata["g(x)"] for state in tr ]
end
3 changes: 3 additions & 0 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ for linesearches in [BackTracking(),StrongWolfe(),HagerZhang(),MoreThuente()] #S
@test sol.g_calls == sol_real.g_calls
@test all(sol_real.trace[i].stepnorm == sol_real.trace[i].stepnorm for i in 2:sol.iterations)
@test all(norm(sol.trace[i].metadata["f(x)"]) ≈ norm(sol_real.trace[i].metadata["f(x)"]) for i in 1:5)
NLsolve.x_trace(sol_real)
NLsolve.F_trace(sol_real)
NLsolve.J_trace(sol_real)
end
end