Skip to content

Commit

Permalink
reduce with | and & passed for arrays longer than 16.
Browse files Browse the repository at this point in the history
  • Loading branch information
lindahua committed Apr 16, 2015
1 parent 0a9f6c9 commit a54e9d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ prod(A::AbstractArray{Bool}) =

## maximum & minimum

function mapreduce_impl(f, op::MaxFun, A::AbstractArray{Bool}, first::Int, last::Int)
function mapreduce_impl(f, op::MaxFun, A::AbstractArray, first::Int, last::Int)
# locate the first non NaN number
v = f(A[first])
i = first + 1
Expand All @@ -241,7 +241,7 @@ function mapreduce_impl(f, op::MaxFun, A::AbstractArray{Bool}, first::Int, last:
v
end

function mapreduce_impl(f, op::MinFun, A::AbstractArray{Bool}, first::Int, last::Int)
function mapreduce_impl(f, op::MinFun, A::AbstractArray, first::Int, last::Int)
# locate the first non NaN number
v = f(A[first])
i = first + 1
Expand Down 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
8 changes: 4 additions & 4 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ 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), 3)) == trues(5)
@test reduce(|, fill(falses(5), 3)) == falses(5)
@test reduce(&, fill(trues(5), 3)) == trues(5)
@test reduce(&, fill(falses(5), 3)) == falses(5)
@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

Expand Down

0 comments on commit a54e9d5

Please sign in to comment.