joshday / OnlineStats.jl

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

Odd interaction of `Group` with broadcast #275

Closed adienes closed 7 months ago

adienes commented 7 months ago

this was a little unexpected to me, as ordinarily foo.(x) is equivalent to map(foo, x)

julia> g = Group(Mean(), Variance())
Group
├─ Mean: n=0 | value=0.0
└─ Variance: n=0 | value=1.0

julia> value.(g)
(Mean: n=0 | value=0.0, Variance: n=0 | value=1.0)

julia> map(value, g)
2-element Vector{Float64}:
 0.0
 1.0
joshday commented 7 months ago

I'm more surprised that map(value, g) works here, actually. The following method is in OnlineStatsBase, so OnlineStats opt out of the broadcast stuff:

Broadcast.broadcastable(o::OnlineStat) = Ref(o)

According to git blame, I apparently accepted a PR from someone 4 years ago (!) that added it. I don't know the reason, but there must have been one for adding it. At this point I think it's too breaking to remove it.

adienes commented 7 months ago

ok, thanks for the explanation (also I just realized I can use values anyway)

I suspect map works because iterate works. And I suppose it wouldn't be the first object that iterates differently from broadcasting, e.g. String