Package pygeodesy :: Module fmath :: Class Fsum
[frames] | no frames]

Class Fsum

object --+
         |
        Fsum

Precision floating point summation similar to standard Python function math.fsum.

Unlike math.fsum, this class accumulates the values incrementally and provides intermediate, precision, running sums. Accumulation may continue after intermediate summations.


Note: Exception and non-finite handling differ from math.fsum.

See Also: Hettinger, Kahan, Klein, Python 2.6+ file Modules/mathmodule.c and the issue log Full precision summation.

Instance Methods
 
__init__(self, *starts)
Initialize a new accumulator with one or more start values.
 
__len__(self)
Return the number of accumulated values.
 
fadd(self, *args)
Accumulate more values from positional arguments.
 
fmul(self, factor)
Multiple the current, partial sum by a factor.
 
fsum_(self, *args)
Accumulated more values from positional arguments and sum all.
 
fsum(self, iterable=())
Accumulated more values from the iterable and sum all.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, *starts)
(Constructor)

 

Initialize a new accumulator with one or more start values.

Parameters:
  • starts - No, one or more start values (scalars).
Raises:
  • OverflowError - Partial 2sum overflow.
  • TypeError - Non-scalar starts value.
  • ValueError - Invalid or infinite starts value.
Overrides: object.__init__

fadd(self, *args)

 

Accumulate more values from positional arguments.

Parameters:
  • args - Values to add (scalars), all positional.
Raises:
  • OverflowError - Partial 2sum overflow.
  • TypeError - Non-scalar args value.
  • ValueError - Invalid or infinite arg.

fmul(self, factor)

 

Multiple the current, partial sum by a factor.

Parameters:
  • factor - The multiplier (scalar).
Raises:
  • TypeError - Non-scalar factor.
  • ValueError - Invalid or infinite factor.

fsum_(self, *args)

 

Accumulated more values from positional arguments and sum all.

Parameters:
  • args - Values to add (scalars), all positional.
Returns:
Accurate, running sum (float).
Raises:
  • OverflowError - Partial 2sum overflow.
  • TypeError - Non-scalar args value.
  • ValueError - Invalid or infinite args value.

Note: Accumulation can continue after summation.

fsum(self, iterable=())

 

Accumulated more values from the iterable and sum all.

Parameters:
  • iterable - Sequence, list, tuple, etc. (scalars), optional.
Returns:
Accurate, running sum (float).
Raises:
  • OverflowError - Partial 2sum overflow.
  • TypeError - Non-scalar iterable value.
  • ValueError - Invalid or infinite iterable value.

Note: Accumulation can continue after summation.