Stream: helpdesk (published)

Topic: are `OnlineStats` thread safe?


view this post on Zulip peter j. (May 22 2021 at 01:45):

for example if I have a m= Mean() can I call fit!(m,some_number) from multiple threads and get correct answers?

a quick google did not turn up much

view this post on Zulip Takafumi Arakaki (tkf) (May 22 2021 at 02:32):

Usually, in-place functions like fit! cannot be used to mutate shared objects concurrently from multiple tasks. If you want to use OnlineStats.jl with threads, you'd need to create the OnlineStat object for each task and merge them using _merge! API: https://github.com/joshday/OnlineStatsBase.jl#interface

view this post on Zulip Takafumi Arakaki (tkf) (May 22 2021 at 02:33):

If you want a quick approach, ThreadsX.jl can be used with OnlineStats.jl as in ThreadsX.reduce(Mean(), 1:10): https://github.com/tkf/ThreadsX.jl#onlinestatsjl


Last updated: Oct 02 2023 at 04:34 UTC