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

# Class Fsum

    object --+
             |
            Fsum

Known Subclasses:
  - Fdot
  - , Fhorner
  - , Fpolynomial

Precision summation similar to standard Python function `math.fsum`.

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

Note: Handling of exceptions, `inf`, `INF`, `nan` and `NAN` values is different 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. |
__add__(self, other) Sum of this and an other instance or a scalar. |
__iadd__(self, other) Add a scalar or an other instance to this instance. |
__imul__(self, other) Multiply this instance by a scalar or an other instance. |
__isub__(self, other) Subtract a scalar or an other instance from this instance. |
__len__(self) Return the number of accumulated values. |
__mul__(self, other) Product of this and an other instance or a scalar. |
__str__(self) str(x) |
__sub__(self, other) Difference of this and an other instance or a scalar. |
fadd(self, xs) Accumulate more values from an iterable. |
fadd_(self, *xs) Accumulate more values from positional arguments. |
fcopy(self, deep=False) Copy this instance, `shallow` or `deep`. |
copy(self, deep=False) Copy this instance, `shallow` or `deep`. |
fmul(self, factor) Multiple the current, partial sum by a factor. |
fsub(self, iterable) Accumulate more values from an iterable. |
fsub_(self, *xs) Accumulate more values from positional arguments. |
fsum(self, iterable=`(``)`) Accumulate more values from an iterable and sum all. |
fsum_(self, *xs) Accumulate more values from positional arguments and sum all. |
fsum2_(self, *xs) Accumulate more values from positional arguments, sum all and provide the sum and delta. |
Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Class Variables
| _fsum2_ = `None` hash(x)

Properties
Inherited from `object`: `__class__`

Method Details

### __init__ (self, *starts) (Constructor) |
Initialize a new accumulator with one or more start values. Arguments: `starts` - No, one or more start values (`scalar`s). Raises: `OverflowError` - Partial `2sum` overflow. `TypeError` - Non-scalar `starts` value. `ValueError` - Invalid or non-finite `starts` value. Overrides: object.__init__

### __add__ (self, other) (Addition operator) |
Sum of this and an other instance or a scalar. Arguments: `other` - Fsum instance or `scalar`. Returns: The sum, a new instance (Fsum). See Also: Method Fsum.__iadd__.

### __iadd__ (self, other) |
Add a scalar or an other instance to this instance. Arguments: `other` - Fsum instance or `scalar`. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.fadd.

### __imul__ (self, other) |
Multiply this instance by a scalar or an other instance. Arguments: `other` - Fsum instance or `scalar`. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.fmul.

### __isub__ (self, other) |
Subtract a scalar or an other instance from this instance. Arguments: `other` - Fsum instance or `scalar`. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.fadd.

### __mul__ (self, other) |
Product of this and an other instance or a scalar. Arguments: `other` - Fsum instance or `scalar`. Returns: The product, a new instance (Fsum). See Also: Method Fsum.__imul__.

### __str__ (self) (Informal representation operator) |
str(x) Overrides: object.__str__ (inherited documentation)

### __sub__ (self, other) (Subtraction operator) |
Difference of this and an other instance or a scalar. Arguments: `other` - Fsum instance or `scalar`. Returns: The difference, a new instance (Fsum). See Also: Method Fsum.__isub__.

### fadd (self, xs) |
Accumulate more values from an iterable. Arguments: `xs` - Iterable, list, tuple, etc. (`scalar`s). Raises: `OverflowError` - Partial `2sum` overflow. `TypeError` - Non-scalar `xs` value. `ValueError` - Invalid or non-finite `xs` value.

### fadd_ (self, *xs) |
Accumulate more values from positional arguments. Arguments: `xs` - Values to add (`scalar`s), all positional. Raises: `OverflowError` - Partial `2sum` overflow. `TypeError` - Non-scalar `xs` value. `ValueError` - Invalid or non-finite `xs` value.

### fcopy (self, deep=False) |
Copy this instance, `shallow` or `deep`. Returns: The copy, a new instance (Fsum).

### copy (self, deep=False) |
Copy this instance, `shallow` or `deep`. Returns: The copy, a new instance (Fsum).

### fmul (self, factor) |
Multiple the current, partial sum by a factor. Arguments: `factor` - The multiplier (`scalar`). Raises: `TypeError` - Non-scalar `factor`. `ValueError` - Invalid or non-finite `factor`. See Also: Method Fsum.fadd.

### fsub (self, iterable) |
Accumulate more values from an iterable. Arguments: `iterable` - Sequence, list, tuple, etc. (`scalar`s). See Also: Method Fsum.fadd.

### fsub_ (self, *xs) |
Accumulate more values from positional arguments. Arguments: `xs` - Values to subtract (`scalar`s), all positional. See Also: Method Fsum.fadd.

### fsum (self, iterable=`(``)`) |
Accumulate more values from an iterable and sum all. Arguments: `iterable` - Sequence, list, tuple, etc. (`scalar`s), optional. Returns: Accurate, running sum (`float`). Raises: `OverflowError` - Partial `2sum` overflow. `TypeError` - Non-scalar `iterable` value. `ValueError` - Invalid or non-finite `iterable` value. Note: Accumulation can continue after summation.

### fsum_ (self, *xs) |
Accumulate more values from positional arguments and sum all. Arguments: `xs` - Values to add (`scalar`s), all positional. Returns: Accurate, running sum (`float`). See Also: Method Fsum.fsum. Note: Accumulation can continue after summation.

### fsum2_ (self, *xs) |
Accumulate more values from positional arguments, sum all and provide the sum and delta. Arguments: `xs` - Values to add (`scalar`s), all positional. Returns: 2-Tuple `(sum, delta)` with the accurate, running `sum` and the `delta` with the previous running `sum`, both (`float`). See Also: Method Fsum.fsum_. Note: Accumulation can continue after summation.