-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behavior
Description
julia/base/multidimensional.jl
Lines 1105 to 1129 in 9a0e797
function copyto!(dest::AbstractArray{T1,N}, Rdest::CartesianIndices{N}, | |
src::AbstractArray{T2,N}, Rsrc::CartesianIndices{N}) where {T1,T2,N} | |
isempty(Rdest) && return dest | |
if size(Rdest) != size(Rsrc) | |
throw(ArgumentError("source and destination must have same size (got $(size(Rsrc)) and $(size(Rdest)))")) | |
end | |
checkbounds(dest, first(Rdest)) | |
checkbounds(dest, last(Rdest)) | |
checkbounds(src, first(Rsrc)) | |
checkbounds(src, last(Rsrc)) | |
src′ = unalias(dest, src) | |
ΔI = first(Rdest) - first(Rsrc) | |
if @generated | |
quote | |
@nloops $N i (n->Rsrc.indices[n]) begin | |
@inbounds @nref($N,dest,n->i_n+ΔI[n]) = @nref($N,src′,i) | |
end | |
end | |
else | |
for I in Rsrc | |
@inbounds dest[I + ΔI] = src′[I] | |
end | |
end | |
dest | |
end |
Now that CartesianIndices
may contain StepRange
s, the implementation doesn't seem correct.
julia> a = rand(4)
4-element Vector{Float64}:
0.7766672217743518
0.5138339000883105
0.7793932733439368
0.6377375487030642
julia> b = zeros(2);
julia> copyto!(b, CartesianIndices(b), a, CartesianIndices((1:2:3,)))
2-element Vector{Float64}:
0.7766672217743518
0.0
julia> a[CartesianIndices((1:2:3,))]
2-element Vector{Float64}:
0.7766672217743518
0.7793932733439368
N5N3
Metadata
Metadata
Assignees
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behavior