Skip to content

Modern Math Merge

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Math Library › Math Library › Merge

Merge

Combines another accumulator's values into this one, exactly.

Syntax

RunningStats.Merge( byref other as RunningStats )

Notes

  • What makes RunningStats parallelisable: each worker accumulates its own, and the results merge at the end into exactly the statistics one pass would have produced.
  • Merging is exact, not an approximation -- the combined mean and variance are computed from both counts and both means.
  • Merging an empty accumulator changes nothing.

Examples

#import "std/numeric"
using numeric

dim a as RunningStats
dim b as RunningStats

for i as int32 = 1 to 3 : a.Add( i ) : next
for i as int32 = 4 to 6 : b.Add( i ) : next

a.Merge( b )
print a.Count( )             '' 6
print a.Mean( )              '' 3.5

'' Exactly what one pass over 1..6 would have given

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally