Skip to content

Commit 255aff6

Browse files
authored
Fix undef writes in setindex take 2 (#173)
* add unit tests for range setindex * Fix issue * Bump patch version
1 parent 8b538f3 commit 255aff6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DiskArrays"
22
uuid = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
33
authors = ["Fabian Gans <[email protected]>"]
4-
version = "0.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"

src/diskarray.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,16 @@ function setindex_disk_batch!(a,v,i)
293293
for (output_indices, temparray_indices, data_indices) in zip(moutput_indices, mtemparray_indices, mdata_indicess)
294294
transfer_results_write!(v, temparray, output_indices, temparray_indices)
295295
vtemparray = maybeshrink(temparray, a, data_indices)
296+
if any(ind->is_sparse_index(ind,density_threshold=1.0),temparray_indices)
297+
readblock!(a, vtemparray, data_indices...)
298+
transfer_results_write!(v, temparray, output_indices, temparray_indices)
299+
end
296300
writeblock!(a, vtemparray, data_indices...)
297301
end
298302
end
299303

300304
function setindex_disk_nobatch!(a,v,i)
301-
indices = resolve_indices(a, i, NoBatch())
305+
indices = resolve_indices(a, i, NoBatch(batchstrategy(a)))
302306
outalias = output_aliasing(indices,ndims(a),ndims(v))
303307
if outalias === :identical
304308
writeblock!(a, v, indices.data_indices...)
@@ -307,6 +311,13 @@ function setindex_disk_nobatch!(a,v,i)
307311
writeblock!(a, temparray, indices.data_indices...)
308312
else
309313
temparray = Array{eltype(a)}(undef, indices.temparray_size...)
314+
if any(ind->is_sparse_index(ind,density_threshold=1.0),indices.temparray_indices)
315+
#We have some sparse indexing pattern and are not in a batch situation, so
316+
#we need to read before writing
317+
#This check could be optimized away in some cases, when writing unit ranges etc,
318+
#but is probably not too expensive
319+
readblock!(a, temparray, indices.data_indices...)
320+
end
310321
transfer_results_write!(v, temparray, indices.output_indices, indices.temparray_indices)
311322
writeblock!(a, temparray, indices.data_indices...)
312323
end

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,18 @@ end
526526
b[mask] = fill(2.0, 4)
527527
@test_broken setindex_count(b) == 4
528528

529+
b = AccessCountDiskArray(zeros(4, 5, 1); chunksize=(4, 1, 1), batchstrategy=DiskArrays.ChunkRead())
530+
b[1:2:4, 1] = [1, 2]
531+
@test b.parent[1:3, 1] == [1, 0, 2]
532+
@test getindex_count(b) == 1
533+
@test setindex_count(b) == 1
534+
535+
b = AccessCountDiskArray(zeros(4, 5, 1); chunksize=(4, 1, 1), batchstrategy=DiskArrays.SubRanges(DiskArrays.CanStepRange(), 1.0))
536+
b[1:2:4, 1] = [1, 2]
537+
@test b.parent[1:3, 1] == [1, 0, 2]
538+
@test getindex_count(b) == 0
539+
@test setindex_count(b) == 1
540+
529541
#Test for #131
530542
a = reshape(1:75,5,5,3)
531543
a1 = AccessCountDiskArray(a);

0 commit comments

Comments
 (0)