From 9a0020d08a2fd6489bba2e751fc22cec4e2f40fe Mon Sep 17 00:00:00 2001 From: joshday Date: Tue, 22 Sep 2020 09:04:25 -0400 Subject: [PATCH] fix variance value type --- src/stats.jl | 2 +- test/test_stats.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/stats.jl b/src/stats.jl index 65f5a37..b955f7f 100644 --- a/src/stats.jl +++ b/src/stats.jl @@ -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 diff --git a/test/test_stats.jl b/test/test_stats.jl index bb66150..fe82800 100644 --- a/test/test_stats.jl +++ b/test/test_stats.jl @@ -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" \ No newline at end of file