Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to new init keyword for reduce family of functions #215

Merged
merged 1 commit into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/array/ArrayBenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ acomplex = samerand(Complex{Float64}, 10^3)
g = addgroup!(SUITE, "reductions", ["sum", "array", "reduce"])
norm1(x) = norm(x, 1)
norminf(x) = norm(x, Inf)
perf_reduce(x) = reduce((x,y) -> x + 2y, real(zero(eltype(x))), x)
perf_mapreduce(x) = mapreduce(x -> real(x)+imag(x), (x,y) -> x + 2y, real(zero(eltype(x))), x)
if VERSION < v"0.7.0-beta-81"
perf_reduce(x) = reduce((x,y) -> x + 2y, real(zero(eltype(x))), x)
perf_mapreduce(x) = mapreduce(x -> real(x)+imag(x), (x,y) -> x + 2y, real(zero(eltype(x))), x)
else
perf_reduce(x) = reduce((x,y) -> x + 2y, x; init=real(zero(eltype(x))))
perf_mapreduce(x) = mapreduce(x -> real(x)+imag(x), (x,y) -> x + 2y, x; init=real(zero(eltype(x))))
end
for a in (afloat, aint)
for fun in (sum, norm, norm1, norminf, mean, perf_reduce, perf_mapreduce)
g[string(fun), string(eltype(a))] = @benchmarkable $fun($a)
Expand Down
17 changes: 13 additions & 4 deletions src/array/sumindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,20 @@ function setup_mapr_access(A)
B = Vector{typeof(zz)}(undef, n)
B, zz, n
end
function perf_mapr_access(A, B, zz, n) #20517
@inbounds for j in 1:n
B[j] = mapreduce(k -> A[j,k]*A[k,j], +, zz, 1:j)
if VERSION < v"0.7.0-beta-81"
function perf_mapr_access(A, B, zz, n) #20517
@inbounds for j in 1:n
B[j] = mapreduce(k -> A[j,k]*A[k,j], +, zz, 1:j)
end
B
end
else
function perf_mapr_access(A, B, zz, n) #20517
@inbounds for j in 1:n
B[j] = mapreduce(k -> A[j,k]*A[k,j], +, 1:j; init=zz)
end
B
end
B
end

##########################
Expand Down