@@ -160,27 +160,13 @@ known_length(::Type{<:Tuple{Vararg{Any,N}}}) where {N} = N
160160known_length (:: Type{<:Number} ) = 1
161161known_length (:: Type{<:AbstractCartesianIndex{N}} ) where {N} = N
162162known_length (:: Type{T} ) where {T} = _maybe_known_length (Base. IteratorSize (T), T)
163-
164- @generated function _prod_or_nothing (x:: Tuple )
165- p = 1
166- for i in eachindex (x. parameters)
167- x. parameters[i] === Nothing && return nothing
168- p *= x. parameters[i]. parameters[1 ]
169- end
170- StaticInt (p)
163+ function known_length (:: Type{<:Iterators.Flatten{I}} ) where {I}
164+ _prod_or_nothing ((known_length (I),known_length (eltype (I))))
171165end
172166
173- function _maybe_known_length (:: Base.HasShape , :: Type{T} ) where {T}
174- t = map (_static_or_nothing, known_size (T))
175- _int_or_nothing (_prod_or_nothing (t))
176- end
167+ _prod_or_nothing (x:: Tuple{Vararg{Int}} ) = prod (x)
168+ _prod_or_nothing (_) = nothing
177169
170+ _maybe_known_length (:: Base.HasShape , :: Type{T} ) where {T} = _prod_or_nothing (known_size (T))
178171_maybe_known_length (:: Base.IteratorSize , :: Type ) = nothing
179- _static_or_nothing (:: Nothing ) = nothing
180- @inline _static_or_nothing (x:: Int ) = StaticInt {x} ()
181- _int_or_nothing (:: StaticInt{N} ) where {N} = N
182- _int_or_nothing (:: Nothing ) = nothing
183- function known_length (:: Type{<:Iterators.Flatten{I}} ) where {I}
184- _int_or_nothing (_prod_or_nothing ((_static_or_nothing (known_length (I)),_static_or_nothing (known_length (eltype (I))))))
185- end
186172
0 commit comments