Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/array/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ function darray_copyto!(B::DArray{TB,NB}, A::DArray{TA,NA}, Binds=parentindices(
Binds_range = ntuple(i->to_range(pad1range(Binds, i)), Nmax)
Ainds_range = ntuple(i->to_range(pad1range(Ainds, i)), Nmax)

# Nothing to copy. Returning here also keeps the chunk ranges below from
# being derived from an empty element range, whose `start` can sit past the
# end of the array (and so outside the chunk grid).
any(isempty, Binds_range) && return B

# Global element offsets
Binds_offset = ntuple(i->Binds_range[i].start-1, Nmax)
Ainds_offset = ntuple(i->Ainds_range[i].start-1, Nmax)
Expand Down
17 changes: 17 additions & 0 deletions test/array/copyto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,20 @@ parts_to_test = map(sz->Blocks(sz...), sizes_to_test)
@testset "Partitioning=$partB<-$partA ($sz)" for partB in parts_to_test, partA in parts_to_test, sz in sizes_to_test
test_copyto(sz, partA, partB, Float64)
end

@testset "empty index ranges" begin
# An empty range whose `start` is past the end of the array is still a valid,
# no-op copy. The chunk range it implies (`fld1(start):fld1(stop)`) can be
# non-empty and point outside the chunk grid, so this used to throw.
A = distribute(zeros(16, 16), Blocks(4, 4))
B = distribute(ones(16, 16), Blocks(4, 4))
reference = collect(A)
@testset "rows=$rows" for rows in (1:0, 5:4, 16:15, 17:16, 18:17, 20:19)
A[rows, 1] = @view B[rows, 1]
@test collect(A) == reference
end
@testset "cols=$cols" for cols in (1:0, 18:17)
A[1, cols] = @view B[1, cols]
@test collect(A) == reference
end
end
Loading