Stream: helpdesk (published)

Topic: ✔ Stencil Iterator


view this post on Zulip Mason Protter (Oct 02 2021 at 22:08):

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?

view this post on Zulip Takafumi Arakaki (tkf) (Oct 02 2021 at 23:05):

Maybe https://juliacollections.github.io/IterTools.jl/latest/#partition(xs,-n,-[step])-1 ?

view this post on Zulip Takafumi Arakaki (tkf) (Oct 02 2021 at 23:08):

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.)

view this post on Zulip Takafumi Arakaki (tkf) (Oct 02 2021 at 23:09):

There's also Tim Holy's https://github.com/JuliaArrays/TiledIteration.jl

view this post on Zulip Mason Protter (Oct 02 2021 at 23:49):

Thanks! I didn't realize that partition(v, n, 1) did exactly what I wanted. Too bad Iterators.partition doesnt do this

view this post on Zulip Notification Bot (Oct 03 2021 at 00:57):

Mason Protter has marked this topic as resolved.


Last updated: Nov 22 2024 at 04:41 UTC