joshday / OnlineStats.jl

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

Documentation Request: List which Monoids support merge #279

Closed schlichtanders closed 3 months ago

schlichtanders commented 6 months ago

I am trying to use OnlineStats.jl with DTable.jl and while it is a great combination, I often run into the error that merge is not defined for my Monoid of choice.

It would be great if there could be an easy list which Monoids also support merge.

EDIT: As a workaround for now, ~is there some programmatic way to find this list?~ I found the following:

foreach(println, unique(Base.unwrap_unionall(m.sig).parameters[2] for m in methods(OnlineStats._merge!)))
joshday commented 3 months ago

Finally clearing out some old GH notifications...sorry for the delay.

There are a set of ideas swirling around in my head for "OnlineStats 2.0", one of which solves this. My temporary solution is below:


In OnlineStatsBase master, I've removed the fallback _merge! method (which just threw an error), so that this works:

julia> is_mergeable(o::T) where {T <: OnlineStat} = hasmethod(OnlineStats._merge!, Tuple{T,T})

julia> is_mergeable(Mean())
# true

Julia> is_mergeable(CircBuff(Int,5)) 
# false

I've added is_mergeable to OnlineStatsBase (unexported).