~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to base/reduce.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-11-17 19:32:52 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20131117193252-tkrpclguqqebqa35
Tags: 0.2.0+dfsg-3
testsuite-i386.patch: loosen the numerical precision for yet another test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
    n == 0 ? v0 : op(v0, mr_pairwise(f,op,A, 1,n))
163
163
end
164
164
 
 
165
function r_pairwise(op::Function, A::AbstractArray, i1,n)
 
166
    if n < 128
 
167
        @inbounds v = A[i1]
 
168
        for i = i1+1:i1+n-1
 
169
            @inbounds v = op(v,A[i])
 
170
        end
 
171
        return v
 
172
    else
 
173
        n2 = div(n,2)
 
174
        return op(r_pairwise(op,A, i1,n2), r_pairwise(op,A, i1+n2,n-n2))
 
175
    end
 
176
end
 
177
function reduce(op::Function, A::AbstractArray)
 
178
    n = length(A)
 
179
    n == 0 ? op() : r_pairwise(op,A, 1,n)
 
180
end
 
181
function reduce(op::Function, v0, A::AbstractArray)
 
182
    n = length(A)
 
183
    n == 0 ? v0 : op(v0, r_pairwise(op,A, 1,n))
 
184
end
 
185
 
165
186
function any(itr)
166
187
    for x in itr
167
188
        if x