From 79b72831706264dcff50ead3090a50e7a4a3c923 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 13 Sep 2018 13:28:05 -0400 Subject: [PATCH] dont force unroll loop in reductions --- src/mapreduce.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mapreduce.jl b/src/mapreduce.jl index f8092a217..968768fd7 100644 --- a/src/mapreduce.jl +++ b/src/mapreduce.jl @@ -66,18 +66,18 @@ end @generated function _mapreduce(f, op, dims::Colon, nt::NamedTuple{()}, ::Size{S}, a::StaticArray...) where {S} - tmp = [:(a[$j][1]) for j ∈ 1:length(a)] - expr = :(f($(tmp...))) - for i ∈ 2:prod(S) - tmp = [:(a[$j][$i]) for j ∈ 1:length(a)] - expr = :(op($expr, f($(tmp...)))) - end + tmp = [:(a[$j][i]) for j ∈ 1:length(a)] return quote @_inline_meta - @inbounds return $expr + i = 1 + @inbounds s = f($(tmp...)) + @inbounds @simd for i = 2:$(prod(S)) + s = op(s, f($(tmp...))) + end + return s end end - + @generated function _mapreduce(f, op, dims::Colon, nt::NamedTuple{(:init,)}, ::Size{S}, a::StaticArray...) where {S} expr = :(nt.init)