Skip to content

Commit

Permalink
Performance fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed May 8, 2019
1 parent 4618723 commit d627393
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,9 @@ sum!(f::Function, r::AbstractArray, A::AbstractArray;
_sum!(f, r, A, weights; init=init)
_sum!(f, r::AbstractArray, A::AbstractArray, ::Nothing; init::Bool=true) =
mapreducedim!(f, add_sum, initarray!(r, add_sum, init, A), A)
_sum(A, dims, weights) = _sum(identity, A, dims, weights)
_sum(f, A, dims, ::Nothing) = mapreduce(f, add_sum, A, dims=dims)
_sum(A::AbstractArray, dims, w::AbstractArray) =
_sum!(identity, reducedim_init(t -> t*zero(eltype(w)), add_sum, A, dims), A, w)


# Weighted sum
Expand Down Expand Up @@ -807,15 +808,15 @@ function _wsum_general!(R::AbstractArray{S}, A::AbstractArray, w::AbstractVector
for IA in CartesianIndices(indsAt)
IR = Broadcast.newindex(IA, keep, Idefault)
r = R[i1,IR]
@simd for i in axes(A, 1)
@inbounds @simd for i in axes(A, 1)
r += A[i,IA] * w[dim > 1 ? IA[dim-1] : i]
end
R[i1,IR] = r
end
else
for IA in CartesianIndices(indsAt)
IR = Broadcast.newindex(IA, keep, Idefault)
@simd for i in axes(A, 1)
@inbounds @simd for i in axes(A, 1)
R[i,IR] += A[i,IA] * w[dim > 1 ? IA[dim-1] : i]
end
end
Expand Down Expand Up @@ -848,9 +849,6 @@ function _sum!(::typeof(identity), R::AbstractArray, A::AbstractArray{T,N}, w::A
_wsum!(R, A, w, dim, init)
end

_sum(A::AbstractArray, dims, w::AbstractArray) =
_sum!(identity, reducedim_init(t -> t*zero(eltype(w)), add_sum, A, dims), A, w)

##### findmin & findmax #####
# The initial values of Rval are not used if the corresponding indices in Rind are 0.
#
Expand Down

0 comments on commit d627393

Please sign in to comment.