Skip to content

Commit ba263d3

Browse files
authored
Fix findall with an empty CuArray of Bool (#2554)
1 parent e359c04 commit ba263d3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function Base.findall(bools::AnyCuArray{Bool})
2727
I = keytype(bools)
2828
indices = cumsum(reshape(bools, prod(size(bools))))
2929

30-
n = @allowscalar indices[end]
30+
n = isempty(indices) ? 0 : @allowscalar indices[end]
3131
ys = CuArray{I}(undef, n)
3232

3333
if n > 0

test/base/array.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,14 @@ end
478478

479479
@testset "findall" begin
480480
# 1D
481+
@test testf(x->findall(x), rand(Bool, 0))
481482
@test testf(x->findall(x), rand(Bool, 100))
482483
@test testf(x->findall(y->y>0.5, x), rand(100))
483484

484485
# ND
486+
let x = rand(Bool, 0, 0)
487+
@test findall(x) == Array(findall(CuArray(x)))
488+
end
485489
let x = rand(Bool, 10, 10)
486490
@test findall(x) == Array(findall(CuArray(x)))
487491
end

0 commit comments

Comments
 (0)