Skip to content

Commit 32e7df3

Browse files
committed
Update reducedim.jl
1 parent 652b461 commit 32e7df3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

base/reducedim.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ function _mapreducedim!(f, op, R::AbstractArray, A::AbstractArrayOrBroadcasted)
269269
i1 = first(axes1(R))
270270
@inbounds for IA in CartesianIndices(indsAt)
271271
IR = Broadcast.newindex(IA, keep, Idefault)
272-
r = R[i1,IR]
273-
@simd for i in axes(A, 1)
274-
r = op(r, f(A[i, IA]))
275-
end
276-
R[i1,IR] = r
272+
@inline elf(i) = @inbounds f(A[i, IA])
273+
ax1 = axes(A, 1)
274+
# use mapreduce_impl for performance
275+
r = mapreduce_impl(elf, op, ax1, firstindex(ax1), lastindex(ax1))
276+
R[i1,IR] = op(R[i1,IR], r)
277277
end
278278
else
279279
@inbounds for IA in CartesianIndices(indsAt)

0 commit comments

Comments
 (0)