Skip to content

Commit

Permalink
In var, don't compute the mean if provided (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
knuesel authored Jan 22, 2021
1 parent ba90d86 commit 7b56a27
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,19 @@ singleton dimensions are allowed).
"""
var(A::AbstractArray; corrected::Bool=true, mean=nothing, dims=:) = _var(A, corrected, mean, dims)

_var(A::AbstractArray, corrected::Bool, mean, dims) =
varm(A, something(mean, Statistics.mean(A, dims=dims)); corrected=corrected, dims=dims)
function _var(A::AbstractArray, corrected::Bool, mean, dims)
if mean === nothing
mean = Statistics.mean(A, dims=dims)
end
return varm(A, mean; corrected=corrected, dims=dims)
end

_var(A::AbstractArray, corrected::Bool, mean, ::Colon) =
real(varm(A, something(mean, Statistics.mean(A)); corrected=corrected))
function _var(A::AbstractArray, corrected::Bool, mean, ::Colon)
if mean === nothing
mean = Statistics.mean(A)
end
return real(varm(A, mean; corrected=corrected))
end

varm(iterable, m; corrected::Bool=true) = _var(iterable, corrected, m)

Expand Down

0 comments on commit 7b56a27

Please sign in to comment.