Skip to content

Commit

Permalink
Fix a case of wrong aliasing for setindex (#164)
Browse files Browse the repository at this point in the history
* Fix a case of wrong aliasing for setindex

* Update src/diskarray.jl

Co-authored-by: Rafael Schouten <[email protected]>

* Update src/diskarray.jl

Co-authored-by: Rafael Schouten <[email protected]>

* update version

---------

Co-authored-by: Rafael Schouten <[email protected]>
  • Loading branch information
meggart and rafaqz authored Apr 15, 2024
1 parent b3f3d1e commit c926307
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DiskArrays"
uuid = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
authors = ["Fabian Gans <[email protected]>"]
version = "0.4.1"
version = "0.4.2"

[deps]
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"
Expand Down
8 changes: 4 additions & 4 deletions src/diskarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ splitcs(::Tuple{}, csnow, csrem) = (csnow, csrem)

#Determine wether output and temp array can a) be identical b) share memory through reshape or
# c) need to be allocated individually
function output_aliasing(di::DiskIndex)
function output_aliasing(di::DiskIndex, ndims_dest, ndims_source)
if all(i->isa(i,Union{Int,AbstractUnitRange,Colon}),di.temparray_indices) &&
all(i->isa(i,Union{Int,AbstractUnitRange,Colon}),di.output_indices)
if di.output_size == di.temparray_size
if di.output_size == di.temparray_size && ndims_dest == ndims_source
return :identical
else
return :reshapeoutput
Expand Down Expand Up @@ -229,7 +229,7 @@ function getindex_disk_nobatch!(out,a,i)
indices = resolve_indices(a, i, NoBatch(allow_steprange(a), 1.0))
#@debug output_size, temparray_size, output_indices, temparray_indices, data_indices
outputarray = create_outputarray(out, a, indices.output_size)
outalias = output_aliasing(indices)
outalias = output_aliasing(indices,ndims(outputarray),ndims(a))
if outalias === :identical
readblock!(a, outputarray, indices.data_indices...)
elseif outalias === :reshapeoutput
Expand Down Expand Up @@ -297,7 +297,7 @@ end

function setindex_disk_nobatch!(a,v,i)
indices = resolve_indices(a, i, NoBatch())
outalias = output_aliasing(indices)
outalias = output_aliasing(indices,ndims(a),ndims(v))
if outalias === :identical
writeblock!(a, v, indices.data_indices...)
elseif outalias === :reshapeoutput
Expand Down
15 changes: 7 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function test_setindex(a)
a[1, 1, 1] = 1
a[1, 2] = 2
a[1, 3, 1, 1] = 3
a[2, :] = [1, 2, 3, 4, 5]
a[2:2, :] = [1, 2, 3, 4, 5]
a[3, 3:4, 1, 1] = [3, 4]
# Test bitmask indexing
m = falses(4, 5, 1)
Expand Down Expand Up @@ -468,21 +468,20 @@ end
a = AccessCountDiskArray(reshape(1:20, 4, 5, 1); chunksize=(4, 1, 1))
i = (1:3,:,:)
di = DiskArrays.resolve_indices(a,i,DiskArrays.NoBatch())
@test DiskArrays.output_aliasing(di) == :identical
@test DiskArrays.output_aliasing(di,3,3) == :identical
@test DiskArrays.output_aliasing(di,2,3) == :reshapeoutput
i = (1,:,:)
di = DiskArrays.resolve_indices(a,i,DiskArrays.NoBatch())
@test DiskArrays.output_aliasing(di) == :reshapeoutput
@test DiskArrays.output_aliasing(di,2,2) == :reshapeoutput
i = ([1,3],:,:)
di = DiskArrays.resolve_indices(a,i,DiskArrays.NoBatch())
@test DiskArrays.output_aliasing(di) == :noalign
@test DiskArrays.output_aliasing(di,3,3) == :noalign
i = (1:3,:)
di = DiskArrays.resolve_indices(a,i,DiskArrays.NoBatch())
@test DiskArrays.output_aliasing(di) == :reshapeoutput
@test DiskArrays.output_aliasing(di,2,2) == :reshapeoutput
i = (1:3,:,:,1,1)
di = DiskArrays.resolve_indices(a,i,DiskArrays.NoBatch())
@test DiskArrays.output_aliasing(di) == :identical


@test DiskArrays.output_aliasing(di,3,3) == :identical
end


Expand Down

0 comments on commit c926307

Please sign in to comment.