Skip to content

Commit 01f5d31

Browse files
authored
Fix any and all (#82)
* Fix any and all * v0.8.3 * Throw errors if any/all are non-boolean
1 parent 1fef853 commit 01f5d31

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FillArrays"
22
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
3-
version = "0.8.2"
3+
version = "0.8.3"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -11,8 +11,8 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111
julia = "1"
1212

1313
[extras]
14-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1514
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
15+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1616

1717
[targets]
18-
test = ["Test","Base64"]
18+
test = ["Test", "Base64"]

src/FillArrays.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,20 @@ function any(f::Function, IM::Eye{T}) where T
453453
d1, d2 = size(IM)
454454
(d1 < 1 || d2 < 1) && return false
455455
(d1 > 1 || d2 > 1) && return f(zero(T)) || f(one(T))
456-
return f(one(T))
456+
return any(f(one(T)))
457457
end
458458

459459
function all(f::Function, IM::Eye{T}) where T
460460
d1, d2 = size(IM)
461461
(d1 < 1 || d2 < 1) && return false
462462
(d1 > 1 || d2 > 1) && return f(zero(T)) && f(one(T))
463-
return f(one(T))
463+
return all(f(one(T)))
464464
end
465465

466466
# In particular, these make iszero(Eye(n)) efficient.
467467
# use any/all on scalar to get Boolean error message
468-
any(f::Function, x::AbstractFill) = any(f, getindex_value(x))
469-
all(f::Function, x::AbstractFill) = all(f, getindex_value(x))
468+
any(f::Function, x::AbstractFill) = any(f(getindex_value(x)))
469+
all(f::Function, x::AbstractFill) = all(f(getindex_value(x)))
470470
any(x::AbstractFill) = any(getindex_value(x))
471471
all(x::AbstractFill) = all(getindex_value(x))
472472

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,17 +712,23 @@ end
712712
@testset "all/any" begin
713713
@test any(Ones{Bool}(10)) === all(Ones{Bool}(10)) === any(Fill(true,10)) === all(Fill(true,10)) === true
714714
@test any(Zeros{Bool}(10)) === all(Zeros{Bool}(10)) === any(Fill(false,10)) === all(Fill(false,10)) === false
715+
@test all(b -> ndims(b) == 1, Fill([1,2],10))
716+
@test any(b -> ndims(b) == 1, Fill([1,2],10))
715717
end
716718

717719
@testset "Error" begin
718720
@test_throws TypeError any(exp, Fill(1,5))
719721
@test_throws TypeError all(exp, Fill(1,5))
722+
@test_throws TypeError any(exp, Eye(5))
723+
@test_throws TypeError all(exp, Eye(5))
720724
@test_throws TypeError any(Fill(1,5))
721725
@test_throws TypeError all(Fill(1,5))
722726
@test_throws TypeError any(Zeros(5))
723727
@test_throws TypeError all(Zeros(5))
724728
@test_throws TypeError any(Ones(5))
725729
@test_throws TypeError all(Ones(5))
730+
@test_throws TypeError any(Eye(5))
731+
@test_throws TypeError all(Eye(5))
726732
end
727733
end
728734

0 commit comments

Comments
 (0)