Skip to content

Commit a2a72e9

Browse files
committed
array/copy: Optimized copyto! to/from Array
1 parent 7a8f66d commit a2a72e9

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/array/copy.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,26 @@ function copyto_view!(Bpart, Brange, Apart, Arange)
109109
copyto!(view(Bpart, Brange), view(Apart, Arange))
110110
return
111111
end
112+
113+
function Base.copyto!(B::DArray{T,N}, A::Array{T,N}) where {T,N}
114+
if size(B) != size(A)
115+
# Fallback to the default implementation
116+
return Base.invoke(copyto!, Tuple{AbstractArray, AbstractArray}, B, A)
117+
end
118+
119+
A_view = view(A, B.partitioning)
120+
copyto!(B, A_view)
121+
122+
return B
123+
end
124+
function Base.copyto!(B::Array{T,N}, A::DArray{T,N}) where {T,N}
125+
if size(B) != size(A)
126+
# Fallback to the default implementation
127+
return Base.invoke(copyto!, Tuple{AbstractArray, AbstractArray}, B, A)
128+
end
129+
130+
B_view = view(B, A.partitioning)
131+
copyto!(B_view, A)
132+
133+
return B
134+
end

0 commit comments

Comments
 (0)