@@ -7,15 +7,15 @@ abstract type Constraint end
7
7
struct FixedCount <: Constraint end
8
8
struct FixedSize <: Constraint end
9
9
10
- abstract type AbstractChunksIterator {T,C<: Constraint ,S<: Split } end
10
+ abstract type AbstractChunks {T,C<: Constraint ,S<: Split } end
11
11
12
- struct ViewChunks{T,C<: Constraint ,S<: Split } <: AbstractChunksIterator {T,C,S}
12
+ struct ViewChunks{T,C<: Constraint ,S<: Split } <: AbstractChunks {T,C,S}
13
13
collection:: T
14
14
n:: Int
15
15
size:: Int
16
16
end
17
17
18
- struct IndexChunks{T,C<: Constraint ,S<: Split } <: AbstractChunksIterator {T,C,S}
18
+ struct IndexChunks{T,C<: Constraint ,S<: Split } <: AbstractChunks {T,C,S}
19
19
collection:: T
20
20
n:: Int
21
21
size:: Int
61
61
is_chunkable (:: Any ) = false
62
62
is_chunkable (:: AbstractArray ) = true
63
63
is_chunkable (:: Tuple ) = true
64
- is_chunkable (:: AbstractChunksIterator ) = true
64
+ is_chunkable (:: AbstractChunks ) = true
65
65
66
66
_set_minsize (minsize:: Nothing ) = 1
67
67
function _set_minsize (minsize:: Integer )
@@ -90,12 +90,12 @@ function err_not_chunkable(::T) where {T}
90
90
throw (ArgumentError (" Arguments of type $T are not compatible with chunks, either implement a custom chunks method for your type, or implement the custom type interface (see https://juliafolds2.github.io/ChunkSplitters.jl/dev/)" ))
91
91
end
92
92
93
- Base. firstindex (:: AbstractChunksIterator ) = 1
93
+ Base. firstindex (:: AbstractChunks ) = 1
94
94
95
- Base. lastindex (c:: AbstractChunksIterator ) = length (c)
95
+ Base. lastindex (c:: AbstractChunks ) = length (c)
96
96
97
- Base. length (c:: AbstractChunksIterator {T,FixedCount,S} ) where {T,S} = c. n
98
- Base. length (c:: AbstractChunksIterator {T,FixedSize,S} ) where {T,S} = cld (length (c. collection), max (1 , c. size))
97
+ Base. length (c:: AbstractChunks {T,FixedCount,S} ) where {T,S} = c. n
98
+ Base. length (c:: AbstractChunks {T,FixedSize,S} ) where {T,S} = cld (length (c. collection), max (1 , c. size))
99
99
100
100
Base. getindex (c:: IndexChunks{T,C,S} , i:: Int ) where {T,C,S} = getchunkindices (c, i)
101
101
Base. getindex (c:: ViewChunks{T,C,S} , i:: Int ) where {T,C,S} = @view (c. collection[getchunkindices (c, i)])
@@ -105,7 +105,7 @@ Base.eltype(::IndexChunks{T,C,RoundRobin}) where {T,C} = StepRange{Int,Int}
105
105
Base. eltype (c:: ViewChunks{T,C,Consecutive} ) where {T,C} = typeof (c[firstindex (c)])
106
106
Base. eltype (c:: ViewChunks{T,C,RoundRobin} ) where {T,C} = typeof (c[firstindex (c)])
107
107
108
- function Base. iterate (c:: AbstractChunksIterator , state= firstindex (c))
108
+ function Base. iterate (c:: AbstractChunks , state= firstindex (c))
109
109
if state > lastindex (c)
110
110
return nothing
111
111
else
@@ -117,42 +117,42 @@ end
117
117
# with `@threads` and co, because of the lack of the general definition of
118
118
# `firstindex`, `lastindex`, and `getindex` for `Base.Iterators.Enumerate{<:Any}`. Thus,
119
119
# to avoid using the internal `.itr` property of `Enumerate`, we redefine
120
- # the `iterate` method for `ChunkSplitters.Enumerate{<:AbstractChunksIterator }`.
121
- struct Enumerate{I<: AbstractChunksIterator }
120
+ # the `iterate` method for `ChunkSplitters.Enumerate{<:AbstractChunks }`.
121
+ struct Enumerate{I<: AbstractChunks }
122
122
itr:: I
123
123
end
124
- Base. enumerate (c:: AbstractChunksIterator ) = Enumerate (c)
124
+ Base. enumerate (c:: AbstractChunks ) = Enumerate (c)
125
125
126
- function Base. iterate (ec:: Enumerate{<:AbstractChunksIterator } , state= firstindex (ec. itr))
126
+ function Base. iterate (ec:: Enumerate{<:AbstractChunks } , state= firstindex (ec. itr))
127
127
if state > lastindex (ec. itr)
128
128
return nothing
129
129
else
130
130
return ((state, @inbounds (ec. itr[state])), state + 1 )
131
131
end
132
132
end
133
133
134
- Base. eltype (ec:: Enumerate{<:AbstractChunksIterator {T,C,Consecutive}} ) where {T,C} = Tuple{Int,eltype (ec. itr)}
135
- Base. eltype (ec:: Enumerate{<:AbstractChunksIterator {T,C,RoundRobin}} ) where {T,C} = Tuple{Int,eltype (ec. itr)}
134
+ Base. eltype (ec:: Enumerate{<:AbstractChunks {T,C,Consecutive}} ) where {T,C} = Tuple{Int,eltype (ec. itr)}
135
+ Base. eltype (ec:: Enumerate{<:AbstractChunks {T,C,RoundRobin}} ) where {T,C} = Tuple{Int,eltype (ec. itr)}
136
136
137
- Base. firstindex (:: Enumerate{<:AbstractChunksIterator } ) = 1
137
+ Base. firstindex (:: Enumerate{<:AbstractChunks } ) = 1
138
138
139
- Base. lastindex (ec:: Enumerate{<:AbstractChunksIterator } ) = lastindex (ec. itr)
139
+ Base. lastindex (ec:: Enumerate{<:AbstractChunks } ) = lastindex (ec. itr)
140
140
141
- Base. getindex (ec:: Enumerate{<:AbstractChunksIterator } , i:: Int ) = (i, ec. itr[i])
141
+ Base. getindex (ec:: Enumerate{<:AbstractChunks } , i:: Int ) = (i, ec. itr[i])
142
142
143
- Base. length (ec:: Enumerate{<:AbstractChunksIterator } ) = length (ec. itr)
143
+ Base. length (ec:: Enumerate{<:AbstractChunks } ) = length (ec. itr)
144
144
145
- Base. eachindex (ec:: Enumerate{<:AbstractChunksIterator } ) = Base. OneTo (length (ec. itr))
145
+ Base. eachindex (ec:: Enumerate{<:AbstractChunks } ) = Base. OneTo (length (ec. itr))
146
146
147
147
_empty_itr (:: Type{Consecutive} ) = 0 : - 1
148
148
_empty_itr (:: Type{RoundRobin} ) = 0 : 1 : - 1
149
149
150
150
"""
151
- getchunkindices(c::AbstractChunksIterator , i::Integer)
151
+ getchunkindices(c::AbstractChunks , i::Integer)
152
152
153
153
Returns the range of indices of `collection` that corresponds to the `i`-th chunk.
154
154
"""
155
- function getchunkindices (c:: AbstractChunksIterator {T,C,S} , ichunk:: Integer ) where {T,C,S}
155
+ function getchunkindices (c:: AbstractChunks {T,C,S} , ichunk:: Integer ) where {T,C,S}
156
156
length (c) == 0 && return _empty_itr (S)
157
157
ichunk <= length (c. collection) || throw (ArgumentError (" ichunk must be less or equal to the length of the ChunksIterator" ))
158
158
if C == FixedCount
0 commit comments