53
53
abstract type IteratorSize end
54
54
struct SizeUnknown <: IteratorSize end
55
55
struct HasLength <: IteratorSize end
56
- struct HasShape <: IteratorSize end
56
+ struct HasShape{N} <: IteratorSize end
57
57
struct IsInfinite <: IteratorSize end
58
58
59
59
"""
@@ -63,8 +63,9 @@ Given the type of an iterator, return one of the following values:
63
63
64
64
* `SizeUnknown()` if the length (number of elements) cannot be determined in advance.
65
65
* `HasLength()` if there is a fixed, finite length.
66
- * `HasShape()` if there is a known length plus a notion of multidimensional shape (as for an array).
67
- In this case the [`size`](@ref) function is valid for the iterator.
66
+ * `HasShape{N}()` if there is a known length plus a notion of multidimensional shape (as for an array).
67
+ In this case `N` should give the number of dimensions, and the [`size`](@ref) function is valid
68
+ for the iterator.
68
69
* `IsInfinite()` if the iterator yields values forever.
69
70
70
71
The default value (for iterators that do not define this function) is `HasLength()`.
@@ -75,7 +76,7 @@ result, and algorithms that resize their result incrementally.
75
76
76
77
```jldoctest
77
78
julia> Base.IteratorSize(1:5)
78
- Base.HasShape()
79
+ Base.HasShape{1} ()
79
80
80
81
julia> Base.IteratorSize((2,3))
81
82
Base.HasLength()
@@ -110,7 +111,7 @@ Base.HasEltype()
110
111
IteratorEltype (x) = IteratorEltype (typeof (x))
111
112
IteratorEltype (:: Type ) = HasEltype () # HasEltype is the default
112
113
113
- IteratorSize (:: Type{<:AbstractArray} ) = HasShape ()
114
+ IteratorSize (:: Type{<:AbstractArray{<:Any,N}} ) where {N} = HasShape {N} ()
114
115
IteratorSize (:: Type{Generator{I,F}} ) where {I,F} = IteratorSize (I)
115
116
length (g:: Generator ) = length (g. iter)
116
117
size (g:: Generator ) = size (g. iter)
0 commit comments