Skip to content

Commit b071f66

Browse files
committed
Fix repeat when length = 0
Same problem as in #81, fixed in #300, but for `repeat`.
1 parent 003752f commit b071f66

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/host/base.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
function Base.repeat(a::AbstractGPUVecOrMat, m::Int, n::Int = 1)
44
o, p = size(a, 1), size(a, 2)
55
b = similar(a, o*m, p*n)
6+
if length(b) == 0
7+
return b
8+
end
69
gpu_call(b, a, o, p, m, n; total_threads=n) do ctx, b, a, o, p, m, n
710
j = linear_index(ctx)
811
j > n && return
@@ -23,6 +26,9 @@ end
2326
function Base.repeat(a::AbstractGPUVector, m::Int)
2427
o = length(a)
2528
b = similar(a, o*m)
29+
if length(b) == 0
30+
return b
31+
end
2632
gpu_call(b, a, o, m; total_threads=m) do ctx, b, a, o, m
2733
i = linear_index(ctx)
2834
i > m && return

test/testsuite/base.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ end
184184
@test compare(a-> repeat(a, 5), AT, rand(Float32, 10))
185185
@test compare(a-> repeat(a, 5), AT, rand(Float32, 5, 4))
186186
@test compare(a-> repeat(a, 4, 3), AT, rand(Float32, 10, 15))
187+
@test compare(a-> repeat(a, 0), AT, rand(Float32, 10))
188+
@test compare(a-> repeat(a, 0), AT, rand(Float32, 5, 4))
189+
@test compare(a-> repeat(a, 4, 0), AT, rand(Float32, 10, 15))
187190
end
188191

189192
@testset "permutedims" begin

0 commit comments

Comments
 (0)