Skip to content
Open
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
6 changes: 0 additions & 6 deletions src/host/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ Base.collect(X::AnyGPUArray) = collect_to_cpu(X)
# expects the GPU array type to have linear `copyto!` methods (i.e. accepting an integer
# offset and length) from and to CPU arrays and between GPU arrays.

function Base.copy!(dst::AbstractGPUVector, src::AbstractGPUVector)
axes(dst) == axes(src) || throw(ArgumentError(
"arrays must have the same axes for `copy!`. consider using `copyto!` instead"))
copyto!(dst, src)
end

for (D, S) in ((AnyGPUArray, Array),
(Array, AnyGPUArray),
(AnyGPUArray, AnyGPUArray))
Expand Down
20 changes: 20 additions & 0 deletions test/testsuite/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ end
copy!(dst, src)
@test dst == src
end
@testset "copy! with differently sized vectors will resize the dst" begin
dst = AT(rand(Float32, (5,)))
src = AT(rand(Float32, (10,)))
copy!(dst, src)
@test length(dst) == 10
@test dst == src

dst = AT(rand(Float32, (10,)))
src = AT(rand(Float32, (5,)))
copy!(dst, src)
@test length(dst) == 5
@test dst == src
end

@testset "copy! with differently sized higher dim arrays will error." begin
dst = AT(rand(Float32, (10, 1)))
src = AT(rand(Float32, (5, 1)))
@test_throws Exception copy!(dst, src)
@test_throws Exception copy!(src, dst)
end
end

@testset "copyto!" begin
Expand Down