Skip to content

Commit ec90012

Browse files
authored
Add fast method for copyto!(::Memory, ::Memory) (#55082)
Previously, this method hit the slow generic AbstractArray fallback. Closes #55079 This is an ad-hoc bandaid that really ought to be fixed by resolving #54581.
1 parent 594544d commit ec90012

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

base/genericmemory.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ end
163163

164164
copy(a::T) where {T<:Memory} = ccall(:jl_genericmemory_copy, Ref{T}, (Any,), a)
165165

166+
copyto!(dest::Memory, src::Memory) = copyto!(dest, 1, src, 1, length(src))
166167
function copyto!(dest::Memory, doffs::Integer, src::Memory, soffs::Integer, n::Integer)
167168
n < 0 && _throw_argerror("Number of elements to copy must be non-negative.")
168169
unsafe_copyto!(dest, doffs, src, soffs, n)

test/copy.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ chnlprod(x) = Channel(c->for i in x; put!(c,i); end)
4949

5050
@test_throws Union{BoundsError, ArgumentError} copyto!(dest, 1, src(), 2, 2)
5151
end
52+
53+
v = rand(Float32, 4)
54+
a = Memory{Float32}(v)
55+
b = similar(a)
56+
copyto!(b, a)
57+
@test a == b
58+
59+
c = Memory{Float32}(undef, 3)
60+
@test_throws BoundsError copyto!(c, a)
5261
end
5362

5463
@testset "with CartesianIndices" begin

0 commit comments

Comments
 (0)