Eigen::KahanSum< Scalar > Class Template Reference

Kahan algorithm based accumulator. More...

Public Member Functions

void operator+= (Scalar increment)
 
Scalar value ()
 

Private Attributes

Scalar _correction
 
Scalar _sum
 

Detailed Description

template<typename Scalar>
class Eigen::KahanSum< Scalar >

Kahan algorithm based accumulator.

The Kahan sum algorithm guarantees to bound the error from floating point accumulation to a fixed value, regardless of the number of accumulations performed. Naive accumulation accumulates errors O(N), and pairwise O(logN). However pairwise also requires O(logN) memory while Kahan summation requires O(1) memory, but 4x the operations / latency.

NB! Do not enable associative math optimizations, they may cause the Kahan summation to be optimized out leaving you with naive summation again.

Definition at line 34 of file SparseInverse.h.

Member Function Documentation

◆ operator+=()

template<typename Scalar >
void Eigen::KahanSum< Scalar >::operator+= ( Scalar  increment)
inline

Definition at line 42 of file SparseInverse.h.

42  {
43  const Scalar correctedIncrement = increment + _correction;
44  const Scalar previousSum = _sum;
45  _sum += correctedIncrement;
46  _correction = correctedIncrement - (_sum - previousSum);
47  }

◆ value()

template<typename Scalar >
Scalar Eigen::KahanSum< Scalar >::value ( )
inline

Definition at line 40 of file SparseInverse.h.

40 { return _sum; }

Member Data Documentation

◆ _correction

template<typename Scalar >
Scalar Eigen::KahanSum< Scalar >::_correction
private

Definition at line 37 of file SparseInverse.h.

◆ _sum

template<typename Scalar >
Scalar Eigen::KahanSum< Scalar >::_sum
private

Definition at line 36 of file SparseInverse.h.


The documentation for this class was generated from the following file: