Skip to content

Commit

Permalink
Add option to successful_reports
Browse files Browse the repository at this point in the history
  • Loading branch information
moyner committed Dec 11, 2024
1 parent fa78f27 commit cae8d47
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/timesteps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ end
successful_reports(old_reports, current_reports, step_index, n = 1)
Get the `n` last successful solve reports from all previous reports
(old_reports) and the current ministep set.
(old_reports) and the current ministep set. You can optionally provide a
function that replaces the default definition of `success=r->r[:success]`.
"""
function successful_reports(old_reports, current_reports, step_index, n = 1)
function successful_reports(old_reports, current_reports, step_index, n = 1; success = r -> r[:success])
out = similar(current_reports, 0)
if isfinite(n)
sizehint!(out, n)
Expand All @@ -169,7 +170,7 @@ function successful_reports(old_reports, current_reports, step_index, n = 1)
end

for r in Iterators.reverse(reports)
if !ismissing(r) && r[:success]
if !ismissing(r) && success(r)
push!(out, r)
if length(out) >= n
return out
Expand All @@ -187,12 +188,12 @@ Get last n successful reports starting at the end of `step` and reversing
backwards until `n` values have been found. `n` can be set to `Inf` to produce
all successful reports.
"""
function successful_reports(reports, current_reports = missing; step = length(reports)+1, n = 1)
function successful_reports(reports, current_reports = missing; step = length(reports)+1, n = 1, kwarg...)
if ismissing(current_reports)
step = clamp(step, 1, length(reports))
current_reports = reports[step][:ministeps]
end
return successful_reports(reports, current_reports, step, n)
return successful_reports(reports, current_reports, step, n; kwarg...)
end

"""
Expand Down

0 comments on commit cae8d47

Please sign in to comment.