more robust batches

This commit is contained in:
Mike J Innes 2017-06-09 18:57:18 +01:00
parent 65400f20ab
commit 358ba650ad

View File

@ -1,4 +1,10 @@
import Base: start, next, done, iteratorsize, iteratoreltype, eltype, length
# Simple version
using Base.Iterators: partition
partitionr(xs, n) = take(partition(xs, n), length(xs)÷n)
batches(xs, n) = (Batch([xs...]) for xs in partitionr(xs, n))
# Stateful iteration
@ -40,6 +46,8 @@ end
# Batched
import Base: start, next, done, iteratorsize, iteratoreltype, eltype, length
struct Batched{I<:StatefulIter,S}
itr::I
buf::S