@@ -162,6 +162,8 @@ int64ToDouble i =
162162{-# INLINE int64ToDouble #-}
163163
164164-- | Add the same value to the distribution N times.
165+ -- Mean and variance are computed according to
166+ -- http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm
165167addN :: Distribution -> Double -> Int64 -> IO ()
166168addN distribution (D ## val) (I64 ## n) = IO $ \ s ->
167169 case myStripe distribution of { (IO myStripe') ->
@@ -194,6 +196,11 @@ addN distribution (D## val) (I64## n) = IO $ \s ->
194196 case spinUnlock mba s14 of { s15 ->
195197 (## s15, () ## ) }}}}}}}}}}}}}}}}}}}}}}}}}}}}
196198
199+ -- | Combine 'b' with 'a', writing the result in 'a'. Takes the lock of
200+ -- 'b' while combining, but doesn't otherwise modify 'b'. 'a' is
201+ -- assumed to not be used concurrently.
202+ -- See also:
203+ -- http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
197204combine :: Distrib -> Distrib -> IO ()
198205combine (Distrib bMBA) (Distrib aMBA) = IO $ \ s ->
199206 case spinLock bMBA s of { s1 ->
@@ -232,6 +239,8 @@ combine (Distrib bMBA) (Distrib aMBA) = IO $ \s ->
232239 case readDoubleArray## bMBA minPos' s13 of { (## s14, bMin ## ) ->
233240 case writeDoubleArray## aMBA minPos' bMin s14 of { s15 ->
234241 case maxPos of { (I ## maxPos') ->
242+ -- This is slightly hacky, but ok: see
243+ -- 813aa426be78e8abcf1c7cdd43433bcffa07828e
235244 case readDoubleArray## bMBA maxPos' s15 of { (## s16, bMax ## ) ->
236245 case writeDoubleArray## aMBA maxPos' bMax s16 of { s17 ->
237246 case spinUnlock bMBA s17 of { s18 ->
0 commit comments