I'm looking for an iterator (or transducer) that has the following behaviour (basically like Iterators.partition
)
julia> for i in stencil(1:6, 3)
@show i
end
i = (1, 2, 3)
i = (2, 3, 4)
i = (3, 4, 5)
i = (4, 5, 6)
Does something like this exist somewhere?
Maybe https://juliacollections.github.io/IterTools.jl/latest/#partition(xs,-n,-[step])-1 ?
There's also https://juliafolds.github.io/Transducers.jl/dev/reference/manual/#Transducers.Consecutive if you need to do this operation after some pre-processing (e.g., filtering) and then parallelize it. But it unnecessarily tortures the compiler if you just need to do it on an array. (There probably should be a "fast pass" in Transducers.jl for this.)
There's also Tim Holy's https://github.com/JuliaArrays/TiledIteration.jl
Thanks! I didn't realize that partition(v, n, 1)
did exactly what I wanted. Too bad Iterators.partition
doesnt do this
Mason Protter has marked this topic as resolved.
Last updated: Dec 28 2024 at 04:38 UTC