Skip to content

Commit

Permalink
Define append
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed May 8, 2024
1 parent 228fb9e commit cea4d04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/host/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,12 @@ Base.deepcopy(x::AbstractGPUArray) = copy(x)

# revert of JuliaLang/julia#31929
Base.filter(f, As::AbstractGPUArray) = As[map(f, As)::AbstractGPUArray{Bool}]

# appending

function Base.append!(a::AbstractGPUVector, items::AbstractVector)
n = length(items)
resize!(a, length(a) + n)
copyto!(a, length(a) - n + 1, items, firstindex(items), n)
return a
end
7 changes: 7 additions & 0 deletions test/testsuite/vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
# we don't shrink buffers yet... TODO shrink them... or should we?
@test length(GPUArrays.buffer(x)) == 5

a = Float32[0, 1, 2]
x = AT(a)
append!(x, [3, 4])
@test length(x) == 5
@test x[4] == 3
@test x[5] == 4

x = AT(Array{Float32}(undef, 16))
reshape!(x, (2, 2, 2, 2))
@test size(x) == (2, 2, 2, 2)
Expand Down

0 comments on commit cea4d04

Please sign in to comment.