daphne-project/daphne

Numerically stable summation

開放

#698 建立於 2024年4月22日

 (0 則留言) (0 個反應) (0 位負責人)C++ (84 個分叉)auto 404
good first issue

倉庫指標

星標
 (80 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

It is known that adding up a large number of small floating-point values can lead to significant rounding errors unless a smart summation algorithm is applied. In fact, such a problem can easily be triggered in DAPHNE at the moment.

The following script generates a matrix of 100 M single-precision floating-point values uniformly distributed in [0, 1]. The sum should be roughly 0.5 * 100 M = 50 M = 5.0e+07. However, the output (on my system) is 1.67772e+07.

X = rand(10^4, 10^4, as.f32(0.0), as.f32(1.0), 1, -1);
print(sum(X));

This task is to implement a numerically stable summation in the aggAll-kernel (src/runtime/local/kernels/AggAll.h). The Kahan summation algorithm could be a candidate.

One could extend the task to check in how far other aggregates (e.g., column-wise (AggCol.h), row-wise (AggRow.h), and cumulative (AggCum.h)) or other aggregation functions (e.g., mean, var, stddev) or other values types (f64) are affected by similar problems.

貢獻者指南