Error using CuIterator with Flux.train!

I’m trying to use CuIterator and Flux.train!. Attempting to do so gives an error because train! tries to get the length of the CuIterator. So this:

iter = CuIterator(batch(i) for i in 1:BATCH_COUNT)
Flux.train!(loss, ps, iter, opt)

results in an error:

MethodError: no method matching length(::CuIterator{Base.Generator{UnitRange{Int64}, var"#17#18"}})

It appears that HasLength() is the default for Base.IteratorSize and CuIterator doesn’t specify it, so it uses the default.

I can workaround it by setting it, but… should this be in CUDA.jl, or is there some other way I should be doing this?

 Base.IteratorSize(::Type{<:CuIterator}) = Base.SizeUnknown()

I have seen the same but forgot to make an issue/pr. I think the correct(er) fix is to delegate both HasLength and length to the wrapped iterator.

Right. Thanks for your help! I created an issue.