-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HasLength
for even more Flatten
iterators
#23431
Comments
Even only with |
I think it is desirable for I don't think it is necessary for |
Also, I'm wary of actually using the iterator to compute the length in general, because an arbitrary iterator may have side effects. Think of |
OK, I clearly didn't think it through enough. Would a special case for |
Couldn't we have a special case for any |
I don't think that's possible, because e.g. an This whole thing makes me wish that the interface were to define methods for |
Defining julia> vecs = [rand(100) for _ in 1:100];
julia> @btime collect(Iterators.flatten($vecs));
min 68.875 μs, mean 81.634 μs (9 allocations, 326.55 KiB) # master
min 12.167 μs, mean 17.848 μs (2 allocations, 78.17 KiB) # with length(::Flatten{... I presume much has changed since discussion above in 2017, and in particular OffsetArrays do define length now, and |
I saw these recent changes: #22691, but maybe we can do better.
Even after these changes, the following example (from Discourse) still results in a
SizeUnknown
Flatten
iterator:It would be possible to simply define
and to add
UnitRange
to this list, but maybe it would be nice to do this more generically?Base.iteratorsize
could returnHasLength()
forfl::Flatten
if all iterators infl.it
areHasLength
orHasSize
, andSizeUnknown
otherwise. That would mean thatBase.iteratorsize(::Flatten)
could no longer be optimized into a constant however; is that a big issue?The text was updated successfully, but these errors were encountered: