Skip to content
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
5 changes: 4 additions & 1 deletion src/host/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@ end
# hacky overloads to make simple vcat and hcat with numbers work as expected.
# we can't really make this work in general without Base providing
# a dispatch mechanism for output container type.
#
# Like Base, a leading scalar in `vcat` or `hcat` is one element along the first dimension
# and along the dimension being concatenated, and stretches along every other dimension.
@inline Base.vcat(a::Number, b::AbstractGPUArray) =
vcat(fill!(similar(b, typeof(a), (1,size(b)[2:end]...)), a), b)
@inline Base.hcat(a::Number, b::AbstractGPUArray) =
hcat(fill!(similar(b, typeof(a), (size(b)[1:end-1]...,1)), a), b)
hcat(fill!(similar(b, typeof(a), (1, 1, size(b)[3:end]...)), a), b)


## reshape
Expand Down
7 changes: 6 additions & 1 deletion test/testsuite/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,19 @@ end
@test compare(hcat, AT, rand(Float32, 3), rand(Float32, 3, 3))
@test compare(hcat, AT, rand(Float32, 3, 3), rand(Float32, 3))
@test compare(hcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3))
#@test compare(hcat, AT, rand(Float32, ), rand(Float32, 3, 3))
# like Base, a leading scalar is one row tall and spans the trailing dimensions
@test compare_exact(hcat, AT, rand(Float32), rand(Float32, 1, 2, 3))
@test compare_exact(hcat, AT, Int16(1), fill(Int32(2), 1, 0, 3, 2))
@test_throws DimensionMismatch hcat(1f0, AT(rand(Float32, 3, 3)))
@test_throws DimensionMismatch hcat(1f0, AT(rand(Float32, 2, 0)))
#@test compare(hcat, AT, rand(Float32, 3, 3), rand(Float32))

@test compare(vcat, AT, rand(Float32, 3), rand(Float32, 3))
@test compare(vcat, AT, rand(Float32, 3, 3), rand(Float32, 3, 3))
@test compare(vcat, AT, rand(Float32, ), rand(Float32, 3))
@test compare(vcat, AT, rand(Float32, 3), rand(Float32))
@test compare(vcat, AT, rand(Float32, ), rand(Float32, 3, 3))
@test compare(vcat, AT, rand(Float32), rand(Float32, 1, 2, 3))
#@test compare(vcat, AT, rand(Float32, 3, 3), rand(Float32))

@test compare((a,b) -> cat(a, b; dims=4), AT, rand(Float32, 3, 4), rand(Float32, 3, 4))
Expand Down
Loading