Skip to content

Commit

Permalink
fix variance value type
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Sep 22, 2020
1 parent 17e9388 commit 9a0020d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ function _merge!(o::Variance, o2::Variance)
end
function value(o::Variance{T}) where {T}
if nobs(o) > 1
o.σ2 * bessel(o)
o.σ2 * T(bessel(o))
else
isfinite(mean(o)) ? T(1) ^ 2 : NaN * T(1) ^ 2
end
Expand Down
2 changes: 2 additions & 0 deletions test/test_stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ println(" > Variance")
@test std(Variance()) == 1
@test std(fit!(Variance(), 1)) == 1
@test std(fit!(Variance(), [1, 2])) == sqrt(.5)
# https://github.com/joshday/OnlineStats.jl/issues/217
@test value(fit!(Variance(Float32), randn(Float32, 10))) isa Float32
end

end # end "Test Stats"

0 comments on commit 9a0020d

Please sign in to comment.