Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert #1

Merged
merged 2 commits into from
Jul 2, 2021
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
44 changes: 23 additions & 21 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1009,36 +1009,38 @@ end

function copyto_unaliased!(deststyle::IndexStyle, dest::AbstractArray, srcstyle::IndexStyle, src::AbstractArray)
isempty(src) && return dest
length(dest) >= length(src) || throw(BoundsError(dest, LinearIndices(src)))
destinds, srcinds = LinearIndices(dest), LinearIndices(src)
idf, isf = first(destinds), first(srcinds)
Δi = idf - isf
(checkbounds(Bool, destinds, isf+Δi) & checkbounds(Bool, destinds, last(srcinds)+Δi)) ||
throw(BoundsError(dest, srcinds))
if deststyle isa IndexLinear
if srcstyle isa IndexLinear
Δi = firstindex(dest) - firstindex(src)
for i in eachindex(src)
@inbounds dest[i + Δi] = src[i]
# Single-index implementation
@inbounds for i in srcinds
dest[i + Δi] = src[i]
end
else
j = firstindex(dest) - 1
@inbounds @simd for I in eachindex(src)
dest[j+=1] = src[I]
# Dual-index implementation
i = idf - 1
@inbounds for a in src
dest[i+=1] = a
end
end
else
if srcstyle isa IndexLinear
i = firstindex(src) - 1
@inbounds @simd for J in eachindex(dest)
dest[J] = src[i+=1]
iterdest, itersrc = eachindex(dest), eachindex(src)
if iterdest == itersrc
# Shared-iterator implementation
for I in iterdest
@inbounds dest[I] = src[I]
end
else
iterdest, itersrc = eachindex(dest), eachindex(src)
if iterdest == itersrc
# Shared-iterator implementation
@inbounds @simd for I in itersrc
dest[I] = src[I]
end
else
for (I,J) in zip(itersrc, iterdest)
@inbounds dest[J] = src[I]
end
# Dual-iterator implementation
ret = iterate(iterdest)
@inbounds for a in src
idx, state = ret
dest[idx] = a
ret = iterate(iterdest, state)
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,17 @@ preprocess_args(dest, args::Tuple{}) = ()
# Specialize this method if all you want to do is specialize on typeof(dest)
@inline function copyto!(dest::AbstractArray, bc::Broadcasted{Nothing})
axes(dest) == axes(bc) || throwdm(axes(dest), axes(bc))
# Performance optimization: broadcast!(identity, dest, A) is equivalent to copyto!(dest, A) if indices match
# Performance optimization: broadcast!(identity, dest, A) is equivalent to copyto!(dest, A) if indices match.
# However copyto!(dest, A) is very slow in many cases, implement a faster version here.
if bc.f === identity && bc.args isa Tuple{AbstractArray} # only a single input argument to broadcast!
A = bc.args[1]
if axes(dest) == axes(A)
return copyto!(dest, A)
A′ = broadcast_unalias(dest, A)
iter = IndexStyle(dest) isa IndexCartesian ? dest : A′
@inbounds @simd for I in eachindex(iter)
dest[I] = A′[I]
end
return dest
end
end
bc′ = preprocess(dest, bc)
Expand Down