@@ -129,7 +129,7 @@ function process_index(i::AbstractUnitRange{<:Integer}, cs, ::NoBatch)
129
129
DiskIndex ((length (i),), (length (i),), (Colon (),), (Colon (),), (i,)), Base. tail (cs)
130
130
end
131
131
function process_index (i:: AbstractArray{<:Integer} , cs, :: NoBatch )
132
- indmin, indmax = extrema (i)
132
+ indmin, indmax = isempty (i) ? ( 1 , 0 ) : extrema (i)
133
133
DiskIndex (size (i), ((indmax - indmin + 1 ),), map (_-> Colon (),size (i)), ((i .- (indmin - 1 )),), (indmin: indmax,)), Base. tail (cs)
134
134
end
135
135
function process_index (i:: AbstractArray{Bool,N} , cs, :: NoBatch ) where {N}
144
144
function process_index (i:: AbstractArray{<:CartesianIndex{N}} , cs, :: NoBatch ) where {N}
145
145
csnow, csrem = splitcs (i, cs)
146
146
s = arraysize_from_chunksize .(csnow)
147
- cindmin, cindmax = extrema (view (CartesianIndices (s), i))
147
+ v = view (CartesianIndices (s), i)
148
+ cindmin, cindmax = if isempty (v)
149
+ one (CartesianIndex{N}), zero (CartesianIndex{N})
150
+ else
151
+ extrema (v)
152
+ end
148
153
indmin, indmax = cindmin. I, cindmax. I
149
154
tempsize = indmax .- indmin .+ 1
150
155
tempoffset = cindmin - oneunit (cindmin)
@@ -157,7 +162,7 @@ function process_index(i::CartesianIndices{N}, cs, ::NoBatch) where {N}
157
162
cols = map (_ -> Colon (), i. indices)
158
163
DiskIndex (length .(i. indices), length .(i. indices), cols, cols, i. indices), csrem
159
164
end
160
- splitcs (i:: AbstractArray{<:CartesianIndex} , cs) = splitcs (first (i ). I, (), cs)
165
+ splitcs (i:: AbstractArray{<:CartesianIndex} , cs) = splitcs (oneunit ( eltype (i) ). I, (), cs)
161
166
splitcs (i:: AbstractArray{Bool} , cs) = splitcs (size (i), (), cs)
162
167
splitcs (i:: CartesianIndices , cs) = splitcs (i. indices, (), cs)
163
168
splitcs (i:: CartesianIndex , cs) = splitcs (i. I,(),cs)
@@ -233,13 +238,13 @@ function getindex_disk_nobatch!(out,a,i)
233
238
outputarray = create_outputarray (out, a, indices. output_size)
234
239
outalias = output_aliasing (indices,ndims (outputarray),ndims (a))
235
240
if outalias === :identical
236
- readblock ! (a, outputarray, indices. data_indices... )
241
+ readblock_sizecheck ! (a, outputarray, indices. data_indices... )
237
242
elseif outalias === :reshapeoutput
238
243
temparray = reshape (outputarray,indices. temparray_size)
239
- readblock ! (a, temparray, indices. data_indices... )
244
+ readblock_sizecheck ! (a, temparray, indices. data_indices... )
240
245
else
241
246
temparray = Array {eltype(a)} (undef, indices. temparray_size... )
242
- readblock ! (a, temparray, indices. data_indices... )
247
+ readblock_sizecheck ! (a, temparray, indices. data_indices... )
243
248
transfer_results! (outputarray, temparray, indices. output_indices, indices. temparray_indices)
244
249
end
245
250
outputarray
@@ -297,18 +302,18 @@ function setindex_disk_batch!(a,v,i)
297
302
readblock! (a, vtemparray, data_indices... )
298
303
transfer_results_write! (v, temparray, output_indices, temparray_indices)
299
304
end
300
- writeblock ! (a, vtemparray, data_indices... )
305
+ writeblock_sizecheck ! (a, vtemparray, data_indices... )
301
306
end
302
307
end
303
308
304
309
function setindex_disk_nobatch! (a,v,i)
305
310
indices = resolve_indices (a, i, NoBatch (batchstrategy (a)))
306
311
outalias = output_aliasing (indices,ndims (a),ndims (v))
307
312
if outalias === :identical
308
- writeblock ! (a, v, indices. data_indices... )
313
+ writeblock_sizecheck ! (a, v, indices. data_indices... )
309
314
elseif outalias === :reshapeoutput
310
315
temparray = reshape (v,indices. temparray_size)
311
- writeblock ! (a, temparray, indices. data_indices... )
316
+ writeblock_sizecheck ! (a, temparray, indices. data_indices... )
312
317
else
313
318
temparray = Array {eltype(a)} (undef, indices. temparray_size... )
314
319
if any (ind-> is_sparse_index (ind,density_threshold= 1.0 ),indices. temparray_indices)
@@ -319,7 +324,21 @@ function setindex_disk_nobatch!(a,v,i)
319
324
readblock! (a, temparray, indices. data_indices... )
320
325
end
321
326
transfer_results_write! (v, temparray, indices. output_indices, indices. temparray_indices)
322
- writeblock! (a, temparray, indices. data_indices... )
327
+ writeblock_sizecheck! (a, temparray, indices. data_indices... )
328
+ end
329
+ end
330
+
331
+ " Like `readblock!`, but only exectued when data size to read is not empty"
332
+ function readblock_sizecheck! (x,y,i... )
333
+ if length (y) > 0
334
+ readblock! (x,y,i... )
335
+ end
336
+ end
337
+
338
+ " Like `writeblock!`, but only exectued when data size to read is not empty"
339
+ function writeblock_sizecheck! (x,y,i... )
340
+ if length (y) > 0
341
+ writeblock! (x,y,i... )
323
342
end
324
343
end
325
344
0 commit comments