Skip to content

managed_iteration suggestion #5

@tbreloff

Description

@tbreloff

Currently a managed iteration takes the form:

function managed_iteration!{T<:AbstractArray}(f!::Base.Callable,
                                              mgr::IterationManager,
                                              dest::T,
                                              istate::IterationState{T};
                                              by::Base.Callable=default_by)
    pre_hook(mgr, istate)

    while !(finished(mgr, istate))
        f!(dest, istate.prev)
        update!(istate, dest; by=by)
        iter_hook(mgr, istate)
    end

    post_hook(mgr, istate)
    istate
end

but I think it will be more general if the dest and f!(dest, istate.prev) happen inside the update! call. I may not have a single parameter vector that I want to update in this fashion, and it may be non-trivial or inefficient to make a f! method of this form.

My proposal:

function managed_iteration!(mgr::IterationManager, istate::IterationState)
    pre_hook(mgr, istate)

    while !(finished(mgr, istate))
        update!(mgr, istate)
        iter_hook(mgr, istate)
    end

    post_hook(mgr, istate)
    istate
end

We can add convenience managers/states to reproduce the same form above, but the core loop is more general. Also, we can just have both forms and let multiple dispatch work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions