@@ -29,13 +29,15 @@ struct DiskIndex{N,M,A<:Tuple,B<:Tuple,C<:Tuple}
29
29
data_indices:: C
30
30
end
31
31
function DiskIndex (
32
- output_size:: NTuple{N,<: Integer} ,
33
- temparray_size:: NTuple{M,<: Integer} ,
32
+ output_size:: Tuple{Vararg{ Integer} } ,
33
+ temparray_size:: Tuple{Vararg{ Integer} } ,
34
34
output_indices:: Tuple ,
35
35
temparray_indices:: Tuple ,
36
36
data_indices:: Tuple
37
- ) where {N,M}
38
- DiskIndex (Int .(output_size), Int .(temparray_size), output_indices, temparray_indices, data_indices)
37
+ )
38
+ output_size_int = map (Int, output_size)
39
+ temparray_size_int = map (Int, temparray_size)
40
+ DiskIndex (output_size_int, temparray_size_int, output_indices, temparray_indices, data_indices)
39
41
end
40
42
DiskIndex (a, i) = DiskIndex (a, i, batchstrategy (a))
41
43
DiskIndex (a, i, batch_strategy) =
@@ -54,9 +56,41 @@ function _resolve_indices(chunks, i, indices_pre::DiskIndex, strategy::BatchStra
54
56
indices_new, chunksrem = process_index (inow, chunks, strategy)
55
57
_resolve_indices (chunksrem, tail (i), merge_index (indices_pre, indices_new), strategy)
56
58
end
59
+ # Some (pretty stupid) hacks to get around Base recursion limiting https://github.com/JuliaLang/julia/pull/48059
60
+ # TODO : We can remove these if Base sorts this out.
61
+ # This makes 3 arg type stable
62
+ function _resolve_indices (chunks:: Tuple{<:Any} , i:: Tuple{<:Any} , indices_pre:: DiskIndex , strategy:: BatchStrategy )
63
+ inow = first (i)
64
+ indices_new, chunksrem = process_index (inow, chunks, strategy)
65
+ return merge_index (indices_pre, indices_new)
66
+ end
67
+ # This makes 4 arg type stable
68
+ function _resolve_indices (chunks:: Tuple{<:Any,<:Any} , i:: Tuple{<:Any,<:Any} , indices_pre:: DiskIndex , strategy:: BatchStrategy )
69
+ inow = first (i)
70
+ indices_new, chunksrem = process_index (inow, chunks, strategy)
71
+ return _resolve_indices (chunksrem, tail (i), merge_index (indices_pre, indices_new), strategy)
72
+ end
73
+ # This makes 5 arg type stable
74
+ function _resolve_indices (chunks:: Tuple{<:Any,<:Any,<:Any} , i:: Tuple{<:Any,<:Any,<:Any} , indices_pre:: DiskIndex , strategy:: BatchStrategy )
75
+ inow = first (i)
76
+ indices_new, chunksrem = process_index (inow, chunks, strategy)
77
+ return _resolve_indices (chunksrem, tail (i), merge_index (indices_pre, indices_new), strategy)
78
+ end
79
+ # This makes 6 arg type stable
80
+ function _resolve_indices (chunks:: Tuple{<:Any,<:Any,<:Any,<:Any} , i:: Tuple{<:Any,<:Any,<:Any,<:Any} , indices_pre:: DiskIndex , strategy:: BatchStrategy )
81
+ inow = first (i)
82
+ indices_new, chunksrem = process_index (inow, chunks, strategy)
83
+ return _resolve_indices (chunksrem, tail (i), merge_index (indices_pre, indices_new), strategy)
84
+ end
57
85
# Splat out CartesianIndex as regular indices
58
86
function _resolve_indices (
59
- chunks, i:: Tuple{<:CartesianIndex} , indices_pre:: DiskIndex , strategy:: BatchStrategy
87
+ chunks:: Tuple , i:: Tuple{<:CartesianIndex} , indices_pre:: DiskIndex , strategy:: BatchStrategy
88
+ )
89
+ _resolve_indices (chunks, (Tuple (i[1 ])... , tail (i)... ), indices_pre, strategy)
90
+ end
91
+ # This method is needed to resolve ambiguity
92
+ function _resolve_indices (
93
+ chunks:: Tuple{<:Any} , i:: Tuple{<:CartesianIndex} , indices_pre:: DiskIndex , strategy:: BatchStrategy
60
94
)
61
95
_resolve_indices (chunks, (Tuple (i[1 ])... , tail (i)... ), indices_pre, strategy)
62
96
end
@@ -112,33 +146,48 @@ Calculate indices for `i` the first chunk/s in `chunks`
112
146
Returns a [`DiskIndex`](@ref), and the remaining chunks.
113
147
"""
114
148
process_index (i, chunks, :: NoBatch ) = process_index (i, chunks)
115
- function process_index (i:: CartesianIndex{N} , chunks, :: NoBatch ) where {N}
149
+ function process_index (i:: CartesianIndex{N} , chunks:: Tuple , :: NoBatch ) where {N}
116
150
_, chunksrem = splitchunks (i, chunks)
117
151
di = DiskIndex ((), map (one, i. I), (), (1 ,), map (i -> i: i, i. I))
152
+
118
153
return di, chunksrem
119
154
end
120
155
process_index (inow:: Integer , chunks) =
121
156
DiskIndex ((), (1 ,), (), (1 ,), (inow: inow,)), tail (chunks)
122
157
function process_index (:: Colon , chunks)
123
158
s = arraysize_from_chunksize (first (chunks))
124
- DiskIndex ((s,), (s,), (Colon (),), (Colon (),), (1 : s,),), tail (chunks)
159
+ di = DiskIndex ((s,), (s,), (Colon (),), (Colon (),), (1 : s,),)
160
+ return di, tail (chunks)
125
161
end
126
162
function process_index (i:: AbstractUnitRange{<:Integer} , chunks, :: NoBatch )
127
- DiskIndex ((length (i),), (length (i),), (Colon (),), (Colon (),), (i,)), tail (chunks)
163
+ di = DiskIndex ((length (i),), (length (i),), (Colon (),), (Colon (),), (i,))
164
+ return di:: DiskIndex , tail (chunks):: Tuple
128
165
end
129
166
function process_index (i:: AbstractArray{<:Integer} , chunks, :: NoBatch )
130
167
indmin, indmax = isempty (i) ? (1 , 0 ) : extrema (i)
131
- di = DiskIndex (size (i), ((indmax - indmin + 1 ),), map (_ -> Colon (), size (i)), ((i .- (indmin - 1 )),), (indmin: indmax,))
168
+
169
+ output_size = size (i)
170
+ temparray_size = ((indmax - indmin + 1 ),)
171
+ output_indices = map (_ -> Colon (), size (i))
172
+ temparray_indices = ((i .- (indmin - 1 )),)
173
+ data_indices = (indmin: indmax,)
174
+ di = DiskIndex (output_size, temparray_size, output_indices, temparray_indices, data_indices)
175
+
132
176
return di, tail (chunks)
133
177
end
134
178
function process_index (i:: AbstractArray{Bool,N} , chunks, :: NoBatch ) where {N}
135
179
chunksnow, chunksrem = splitchunks (i, chunks)
136
180
s = arraysize_from_chunksize .(chunksnow)
137
181
cindmin, cindmax = extrema (view (CartesianIndices (s), i))
138
182
indmin, indmax = cindmin. I, cindmax. I
139
- tempsize = indmax .- indmin .+ 1
140
- tempinds = view (i, range .(indmin, indmax)... )
141
- di = DiskIndex ((sum (i),), tempsize, (Colon (),), (tempinds,), range .(indmin, indmax))
183
+
184
+ output_size = (sum (i),)
185
+ temparray_size = map ((max, min) -> max - min + 1 , indmax, indmin)
186
+ output_indices = (Colon (),)
187
+ temparray_indices = (view (i, map (range, indmin, indmax)... ),)
188
+ data_indices = map (range, indmin, indmax)
189
+ di = DiskIndex (output_size, temparray_size, output_indices, temparray_indices, data_indices)
190
+
142
191
return di, chunksrem
143
192
end
144
193
function process_index (i:: AbstractArray{<:CartesianIndex{N}} , chunks, :: NoBatch ) where {N}
@@ -151,17 +200,26 @@ function process_index(i::AbstractArray{<:CartesianIndex{N}}, chunks, ::NoBatch)
151
200
extrema (v)
152
201
end
153
202
indmin, indmax = cindmin. I, cindmax. I
154
- tempsize = indmax .- indmin .+ 1
155
- tempoffset = cindmin - oneunit (cindmin)
156
- tempinds = i .- (CartesianIndex (tempoffset),)
157
- outinds = map (_ -> Colon (), size (i))
158
- di = DiskIndex (size (i), tempsize, outinds, (tempinds,), range .(indmin, indmax))
203
+
204
+ output_size = size (i)
205
+ temparray_size = map ((max, min) -> max - min + 1 , indmax, indmin)
206
+ temparray_offset = cindmin - oneunit (cindmin)
207
+ temparray_indices = (i .- (CartesianIndex (temparray_offset),),)
208
+ output_indices = map (_ -> Colon (), size (i))
209
+ data_indices = map (range, indmin, indmax)
210
+ di = DiskIndex (output_size, temparray_size, output_indices, temparray_indices, data_indices)
211
+
159
212
return di, chunksrem
160
213
end
161
214
function process_index (i:: CartesianIndices{N} , chunks, :: NoBatch ) where {N}
162
215
_, chunksrem = splitchunks (i, chunks)
163
- cols = map (_ -> Colon (), i. indices)
164
- di = DiskIndex (length .(i. indices), length .(i. indices), cols, cols, i. indices)
216
+
217
+ output_size = map (length, i. indices)
218
+ temparray_size = map (length, i. indices)
219
+ output_indices = temparray_indices = map (_ -> Colon (), i. indices)
220
+ data_indices = i. indices
221
+ di = DiskIndex (output_size, temparray_size, output_indices, temparray_indices, data_indices)
222
+
165
223
return di, chunksrem
166
224
end
167
225
0 commit comments