Skip to content

Commit

Permalink
Move isassigned within inbounds in copyto_unaliased (#53311)
Browse files Browse the repository at this point in the history
This matches the other branches where the `isassigned` and `
_unsetindex!` are within `@inbounds` blocks, and this might help with
performance after #53305
  • Loading branch information
jishnub authored Feb 14, 2024
1 parent 09a27b3 commit 52006ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,9 @@ function copyto_unaliased!(deststyle::IndexStyle, dest::AbstractArray, srcstyle:
iterdest, itersrc = eachindex(dest), eachindex(src)
if iterdest == itersrc
# Shared-iterator implementation
for I in iterdest
@inbounds for I in iterdest
if isassigned(src, I)
@inbounds dest[I] = src[I]
dest[I] = src[I]
else
_unsetindex!(dest, I)
end
Expand Down
28 changes: 28 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1979,3 +1979,31 @@ end
test_prechecked_iterate(LinearIndices(()))
test_prechecked_iterate(Base.SCartesianIndices2{3}(1:3))
end

@testset "IndexStyles in copyto!" begin
A = rand(3,2)
B = zeros(size(A))
colons = ntuple(_->:, ndims(B))
# Ensure that the AbstractArray methods are hit
# by using views instead of Arrays
@testset "IndexLinear - IndexLinear" begin
B .= 0
copyto!(view(B, colons...), A)
@test B == A
end
@testset "IndexLinear - IndexCartesian" begin
B .= 0
copyto!(view(B, colons...), view(A, axes(A)...))
@test B == A
end
@testset "IndexCartesian - IndexLinear" begin
B .= 0
copyto!(view(B, axes(B)...), A)
@test B == A
end
@testset "IndexCartesian - IndexCartesian" begin
B .= 0
copyto!(view(B, axes(B)...), view(A, axes(A)...))
@test B == A
end
end

0 comments on commit 52006ae

Please sign in to comment.