Skip to content

Commit fbe5e0d

Browse files
committed
Improve any/all support
1 parent fc8b936 commit fbe5e0d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/FillArrays.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,11 @@ function all(f::Function, IM::Eye{T}) where T
426426
end
427427

428428
# In particular, these make iszero(Eye(n)) efficient.
429-
any(f::Function, x::AbstractFill) = f(getindex_value(x))
430-
all(f::Function, x::AbstractFill) = f(getindex_value(x))
429+
# use any/all on scalar to get Boolean error message
430+
any(f::Function, x::AbstractFill) = any(f, getindex_value(x))
431+
all(f::Function, x::AbstractFill) = all(f, getindex_value(x))
432+
any(x::AbstractFill) = any(getindex_value(x))
433+
all(x::AbstractFill) = all(getindex_value(x))
431434

432435
include("fillalgebra.jl")
433436
include("fillbroadcast.jl")

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,22 @@ end
650650
@test ! iszero(m4)
651651
end
652652
end
653+
654+
@testset "all/any" begin
655+
@test any(Ones{Bool}(10)) === all(Ones{Bool}(10)) === any(Fill(true,10)) === all(Fill(true,10)) === true
656+
@test any(Zeros{Bool}(10)) === all(Zeros{Bool}(10)) === any(Fill(false,10)) === all(Fill(false,10)) === false
657+
end
658+
659+
@testset "Error" begin
660+
@test_throws TypeError any(exp, Fill(1,5))
661+
@test_throws TypeError all(exp, Fill(1,5))
662+
@test_throws TypeError any(Fill(1,5))
663+
@test_throws TypeError all(Fill(1,5))
664+
@test_throws TypeError any(Zeros(5))
665+
@test_throws TypeError all(Zeros(5))
666+
@test_throws TypeError any(Ones(5))
667+
@test_throws TypeError all(Ones(5))
668+
end
653669
end
654670

655671
@testset "Eye identity ops" begin

0 commit comments

Comments
 (0)