Skip to content

Commit 617be46

Browse files
authored
any for an empty array returns false (#203)
* any for empty array returns false * Add test
1 parent 4845062 commit 617be46

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/FillArrays.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,10 @@ end
586586

587587
# In particular, these make iszero(Eye(n)) efficient.
588588
# use any/all on scalar to get Boolean error message
589-
any(f::Function, x::AbstractFill) = isempty(x) || any(f(getindex_value(x)))
589+
any(f::Function, x::AbstractFill) = !isempty(x) && any(f(getindex_value(x)))
590590
all(f::Function, x::AbstractFill) = isempty(x) || all(f(getindex_value(x)))
591-
any(x::AbstractFill) = isempty(x) || any(getindex_value(x))
592-
all(x::AbstractFill) = isempty(x) || all(getindex_value(x))
591+
any(x::AbstractFill) = any(identity, x)
592+
all(x::AbstractFill) = all(identity, x)
593593

594594
count(x::Ones{Bool}) = length(x)
595595
count(x::Zeros{Bool}) = 0

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ end
10431043
@test any(b -> ndims(b) == 1, Fill([1,2],10))
10441044

10451045
@test all(Fill(2,0))
1046-
@test any(Fill(2,0))
1046+
@test !any(Fill(2,0))
1047+
@test any(Trues(2,0)) == any(trues(2,0))
10471048
end
10481049

10491050
@testset "Error" begin

0 commit comments

Comments
 (0)