Skip to content

Commit

Permalink
Merge pull request JuliaLang#10842 from JuliaLang/dh/reduceboolfix
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Apr 16, 2015
2 parents 6877ef0 + a54e9d5 commit b7d7955
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function mapfoldl(f, ::OrFun, itr)
return false
end

function mapreduce_impl(f, op::AndFun, A::AbstractArray, ifirst::Int, ilast::Int)
function mapreduce_impl(f, op::AndFun, A::AbstractArray{Bool}, ifirst::Int, ilast::Int)
while ifirst <= ilast
@inbounds x = A[ifirst]
!f(x) && return false
Expand All @@ -319,7 +319,7 @@ function mapreduce_impl(f, op::AndFun, A::AbstractArray, ifirst::Int, ilast::Int
return true
end

function mapreduce_impl(f, op::OrFun, A::AbstractArray, ifirst::Int, ilast::Int)
function mapreduce_impl(f, op::OrFun, A::AbstractArray{Bool}, ifirst::Int, ilast::Int)
while ifirst <= ilast
@inbounds x = A[ifirst]
f(x) && return true
Expand Down
5 changes: 5 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ prod2(itr) = invoke(prod, (Any,), itr)
@test all(x->x>0, [4]) == true
@test all(x->x>0, [-3, 4, 5]) == false

@test reduce(|, fill(trues(5), 24)) == trues(5)
@test reduce(|, fill(falses(5), 24)) == falses(5)
@test reduce(&, fill(trues(5), 24)) == trues(5)
@test reduce(&, fill(falses(5), 24)) == falses(5)

# in

@test in(1, Int[]) == false
Expand Down

0 comments on commit b7d7955

Please sign in to comment.