Skip to content

Commit

Permalink
fix multiscale iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Aug 13, 2018
1 parent 224b266 commit 03df63a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/level_iterations.jl
Expand Up @@ -5,10 +5,26 @@ struct LevelIterIdx{T}
end
LevelIterIdx(S::AbstractMultiScaleArray, n::Int) = LevelIterIdx(level_iter(S, n))

Base.start(l::LevelIterIdx) = (start(l.iter), 1)
function Base.next(l::LevelIterIdx, state)
start(l::LevelIterIdx) = (start(l.iter), 1)
function next(l::LevelIterIdx, state)
val, new_state = next(l.iter, state[1])
end_idx = state[2] + length(val) - 1
((val, state[2], end_idx), (new_state, end_idx + 1))
end
Base.done(l::LevelIterIdx, state) = done(l.iter, state[1])
done(l::LevelIterIdx, state) = done(l.iter, state[1])

function Base.iterate(l::LevelIterIdx)
x = iterate(l.iter)
x == nothing && return nothing
val, new_state = x
end_idx = 1 + length(val) - 1
((val, 1, end_idx), (new_state, end_idx + 1))
end

function Base.iterate(l::LevelIterIdx,state)
x = iterate(l.iter,state[1])
x == nothing && return nothing
val, new_state = x
end_idx = state[2] + length(val) - 1
((val, state[2], end_idx), (new_state, end_idx + 1))
end

0 comments on commit 03df63a

Please sign in to comment.