Skip to content

Commit 2637011

Browse files
committed
longer argument names
1 parent 6bb3f18 commit 2637011

3 files changed

Lines changed: 44 additions & 43 deletions

File tree

src/interface/algorithm.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ e.g. as accessors
1919
The following methods should be implemented for an [`Algorithm`](@ref)
2020
2121
* [`get_stopping_criterion`](@ref) to return the algorithms stopping criterion.
22+
2223
## Example
2324
2425
For a [gradient descent](https://en.wikipedia.org/wiki/Gradient_descent) algorithm
@@ -27,10 +28,10 @@ the algorithm would specify which step size selection to use.
2728
abstract type Algorithm end
2829

2930
"""
30-
get_stopping_criterion(a::Algorithm)
31+
get_stopping_criterion(algorithm::Algorithm)
3132
32-
Return the [`StoppingCriterion`](@ref) of the [`Algorithm`](@ref) `a`.
33+
Return the [`StoppingCriterion`](@ref) of the [`Algorithm`](@ref).
3334
34-
The default assumes that the criterion is stored in `s.stopping_criterion_state`.
35+
The default assumes that the criterion is stored in `algorithm.stopping_criterion`.
3536
"""
36-
get_stopping_criterion(a::Algorithm) = a.stopping_criterion
37+
get_stopping_criterion(algorithm::Algorithm) = algorithm.stopping_criterion

src/interface/state.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,48 @@ their accessors.
2424
2525
The following methods should be implemented for a state
2626
27-
* [`get_iteration`](@ref)`(s)` to return the current iteration number
28-
* [`increment!](@ref)`(s)`
27+
* [`get_iteration`](@ref)`(state)` to return the current iteration number
28+
* [`increment!](@ref)`(state)`
2929
* [`get_stopping_criterion_state`](@ref) return the [`StoppingCriterionState`](@ref)
3030
* [`get_iterate`](@ref) return the current iterate ``x^{(k)}``.
3131
"""
3232
abstract type State end
3333

3434
"""
35-
get_iterate(s::State)
35+
get_iterate(state::State)
3636
37-
Return the current iterate ``x^{(k)}`` of a [`State`](@ref) `s`
37+
Return the current iterate ``x^{(k)}`` of a [`State`](@ref).
3838
39-
The default assumes that the current iteration is stored in `s.iterate`.
39+
The default assumes that the current iterate is stored in `state.iterate`.
4040
"""
41-
get_iterate(s::State) = s.iterate
41+
get_iterate(state::State) = state.iterate
4242

4343
"""
44-
get_iteration(s::State)
44+
get_iteration(state::State)
4545
46-
Return the current iteration a [`State`](@ref) `s` either is currently performing or was last performed
46+
Return the current iteration a [`State`](@ref) either is currently performing or was last performed
4747
48-
The default assumes that the current iteration is stored in `s.iteration`.
48+
The default assumes that the current iteration is stored in `state.iteration`.
4949
"""
50-
get_iteration(s::State) = s.iteration
50+
get_iteration(state::State) = state.iteration
5151

5252
"""
53-
increment!(s::State)
53+
increment!(state::State)
5454
55-
Return the current iteration a [`State`](@ref) `s` either is currently performing or was last performed
55+
Increment the current iteration a [`State`](@ref) either is currently performing or was last performed
5656
57-
The default assumes that the current iteration is stored in `s.iteration`.
57+
The default assumes that the current iteration is stored in `state.iteration`.
5858
"""
59-
function increment!(s::State)
60-
s.iteration += 1
59+
function increment!(state::State)
60+
state.iteration += 1
6161
return s
6262
end
6363

6464
"""
65-
get_stopping_criterion_state(s::State)
65+
get_stopping_criterion_state(state::State)
6666
67-
Return the [`StoppingCriterionState`](@ref) of the [`State`](@ref) `s`.
67+
Return the [`StoppingCriterionState`](@ref) of the given [`State`](@ref).
6868
69-
The default assumes that the criterion is stored in `s.stopping_criterion_state`.
69+
The default assumes that the criterion is stored in `state.stopping_criterion_state`.
7070
"""
71-
get_stopping_criterion_state(s::State) = s.stopping_criterion_state
71+
get_stopping_criterion_state(state::State) = state.stopping_criterion_state

src/stopping_criterion.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,24 @@ mutable struct GroupStoppingCriterionState{TCriteriaStates<:Tuple} <: StoppingCr
202202
end
203203

204204
function initialize_state(
205-
p::Problem,
206-
a::Algorithm,
205+
problem::Problem,
206+
algorithm::Algorithm,
207207
sc::Union{StopWhenAll,StopWhenAny};
208208
kwargs...,
209209
)
210210
return GroupStoppingCriterionState([
211-
initialize_state(p, a, sc_i; kwargs) for sc_i in sc.criteria
211+
initialize_state(problem, algorithm, sc_i; kwargs) for sc_i in sc.criteria
212212
])
213213
end
214214
function initialize_state!(
215215
scs::GroupStoppingCriterionState,
216-
p::Problem,
217-
a::Algorithm,
216+
problem::Problem,
217+
algorithm::Algorithm,
218218
sc::Union{StopWhenAll,StopWhenAny};
219219
kwargs...,
220220
)
221221
for (scs_i, sc_i) in zip(scs.criteria_states, sc.criteria)
222-
initialize_state!(scs_i, p, a, sc_i; kwargs...)
222+
initialize_state!(scs_i, problem, algorithm, sc_i; kwargs...)
223223
end
224224
scs.at_iteration = -1
225225
return scs
@@ -259,29 +259,29 @@ function Base.summary(io::IO, sc::StopWhenAll, scs::GroupStoppingCriterionState)
259259
end
260260
# Meta functors
261261
function (scs::GroupStoppingCriterionState)(
262-
p::Problem,
263-
a::Algorithm,
264-
s::State,
262+
problem::Problem,
263+
algorithm::Algorithm,
264+
state::State,
265265
sc::StopWhenAll,
266266
)
267-
k = get_iteration(s)
267+
k = get_iteration(state)
268268
(k == 0) && (scs.at_iteration = -1) # reset on init
269-
if all(st -> st[2](p, a, s, st[1]), zip(sc.criteria, scs.criteria_states))
269+
if all(st -> st[2](problem, algorithm, state, st[1]), zip(sc.criteria, scs.criteria_states))
270270
scs.at_iteration = k
271271
return true
272272
end
273273
return false
274274
end
275275

276276
function (scs::GroupStoppingCriterionState)(
277-
p::Problem,
278-
a::Algorithm,
279-
s::State,
277+
problem::Problem,
278+
algorithm::Algorithm,
279+
state::State,
280280
sc::StopWhenAny,
281281
)
282-
k = get_iteration(s)
282+
k = get_iteration(state)
283283
(k == 0) && (c.at_iteration = -1) # reset on init
284-
if any(st -> st[2](p, a, s, st[1]), zip(sc.criteria, scs.criteria_states))
284+
if any(st -> st[2](problem, algorithm, state, st[1]), zip(sc.criteria, scs.criteria_states))
285285
c.at_iteration = k
286286
return true
287287
end
@@ -344,10 +344,10 @@ end
344344
function (scs::DefaultStoppingCriterionState)(
345345
::Problem,
346346
::Algorithm,
347-
s::State,
347+
state::State,
348348
sc::StopAfterIteration,
349349
)
350-
k = get_iteration(s)
350+
k = get_iteration(state)
351351
(k == 0) && (scs.at_iteration = -1)
352352
if k >= sc.max_iterations
353353
scs.at_iteration = k
@@ -434,8 +434,8 @@ function initialize_state!(
434434
return scs
435435
end
436436

437-
function (scs::StopAfterTimePeriodState)(::Problem, ::Algorithm, s::State, sc::StopAfter)
438-
k = get_iteration(s)
437+
function (scs::StopAfterTimePeriodState)(::Problem, ::Algorithm, state::State, sc::StopAfter)
438+
k = get_iteration(state)
439439
if value(scs.start) == 0 || k <= 0 # (re)start timer
440440
scs.at_iteration = -1
441441
scs.start = Nanosecond(time_ns())

0 commit comments

Comments
 (0)