joshday / OnlineStats.jl

⚡ Single-pass algorithms for statistics
https://joshday.github.io/OnlineStats.jl/latest/
MIT License
836 stars 64 forks source link

Variance is not type stable #217

Closed theogf closed 4 years ago

theogf commented 4 years ago

MWE :

v = Variance(Float32)
fit!(v, rand(Float32, 100))
typeof(value(v)) == Float64
joshday commented 4 years ago

Thanks for reporting! That doesn’t demonstrate what people mean by not being type stable, but I see what you mean. The value gets promoted to Float64 by the Bessel correction:

https://github.com/joshday/OnlineStatsBase.jl/blob/17e93888e65a185812c328a006df597327340e9f/src/OnlineStatsBase.jl#L161

I’ve got a fix in mind, should be pretty minor changes.

theogf commented 4 years ago

Ah sorry I thought it was when you pass a Float32 you expect a Float32 (in this case) at the output! A bit off-topic but is there a reason why it's not possible to iterate over MovingWindow (without using value)? It would be nice to be able to use last, first and other iteration tools! :D Thanks a lot for the package it's really amazingly easy to use!

joshday commented 4 years ago

Type stability is when the return type can change depending on the inputs to a method, e.g.

f(x::Int) = x == 1 ? 1 : false

isn't type stable because f(1) and f(2) call the same method but return different types.

why it's not possible to iterate over MovingWindow

Only because I haven't needed it/nobody requested it! You want to give it a shot and make a PR?

Thanks a lot for the package it's really amazingly easy to use!

Thanks for the kind words!

joshday commented 4 years ago

This is now fixed in the latest release.