Skip to content

Commit

Permalink
Cleanup weighted sum (no longer imported from Base)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Sep 25, 2021
1 parent e9728b2 commit 1277ff9
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 262 deletions.
4 changes: 2 additions & 2 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function _mean!(R::AbstractArray, A::AbstractArray, weights::Nothing)
end

_mean!(R::AbstractArray, A::AbstractArray, w::AbstractArray) =
rmul!(_sum!(R, A, weights=w), inv(sum(w)))
rmul!(wsum!(R, A, weights=w), inv(sum(w)))

"""
mean(A::AbstractArray; [dims], [weights::AbstractArray])
Expand Down Expand Up @@ -223,7 +223,7 @@ end

# Note: weighted mean currently does not use _mean_promote to avoid overflow
_mean(::typeof(identity), A::AbstractArray, dims::Colon, w::AbstractArray) =
_sum(A, weights=w) / sum(w)
wsum(A, weights=w) / sum(w)

_mean(::typeof(identity), A::AbstractArray, dims, w::AbstractArray) =
_mean!(Base.reducedim_init(t -> (t*zero(eltype(w)))/2, Base.add_sum, A, dims), A, w)
Expand Down
Loading

0 comments on commit 1277ff9

Please sign in to comment.