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

# Class Fsum

      object --+
               |
    named._Named --+
                   |
                  Fsum

Known Subclasses:
  - fmath.Fdot
  - , fmath.Fhorner
  - , fmath.Fpolynomial

Precision running floating point summation similar to standard Python's `math.fsum`.

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

Notes:

- Handling of exceptions, `inf`, `INF`, `nan` and `NAN` values differs from standard Python's `math.fsum`.
- Values to be accumulated are `scalar` or fsum instances with `scalar` meaning type `float`, `int` or any type convertible to `float`.

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

Instance Methods
__init__(self, *xs, **name_NN) New Fsum for running precision floating point summation. |
__abs__(self) Return this instance' absolute value as an Fsum. |
__add__(self, other) Return the sum `self + other` as an Fsum. |
__bool__(self) Return `True` if this instance is non-zero. |
__ceil__(self) Return this instance' `math.ceil` as `int` or `float`Fsum(. |
__divmod__(self, other) Return `divmod(self, other)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. |
__eq__(self, other) Compare this with an other instance or scalar. |
__float__(self) Return this instance as `float`, without residual. |
__floor__(self) Return this instance' `math.floor` as `int` or `float`. |
__floordiv__(self, other) Return `self // other` as an Fsum. |
__format__(self, *other) Not implemented. |
__ge__(self, other) Compare this with an other instance or scalar. |
__gt__(self, other) Compare this with an other instance or scalar. |
__hash__(self) Return this instance' `hash`. |
__iadd__(self, other) Apply `self += other` to this instance. |
__ifloordiv__(self, other) Apply `self //= other` to this instance. |
__imatmul__(self, other) Not implemented. |
__imod__(self, other) Apply `self %= other` to this instance. |
__imul__(self, other) Apply `self *= other` to this instance. |
__int__(self) Return this instance as an `int`. |
__ipow__(self, other, *mod) Apply `self **= other` to this instance. |
__isub__(self, other) Apply `self -= other` to this instance. |
__iter__(self) Return an `iter`ator over a `partials` duplicate. |
__itruediv__(self, other) Apply `self /= other` to this instance. |
__le__(self, other) Compare this with an other instance or scalar. |
__len__(self) Return the total number of value accumulated (`int`). |
__lt__(self, other) Compare this with an other instance or scalar. |
__matmul__(self, other) Not implemented. |
__mod__(self, other) Return `self % other` as an Fsum. |
__mul__(self, other) Return `self * other` as an Fsum. |
__ne__(self, other) Compare this with an other instance or scalar. |
__neg__(self) Return a copy of this instance, negated. |
__pos__(self) Return this instance, as-is. |
__pow__(self, other, *mod) Return `self ** other` as an Fsum. |
__radd__(self, other) Return `other + self` as an Fsum. |
__rdivmod__(self, other) Return `divmod(other, self)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. |
__rfloordiv__(self, other) Return `other // self` as an Fsum. |
__rmatmul__(self, other) Not implemented. |
__rmod__(self, other) Return `other % self` as an Fsum. |
__rmul__(self, other) Return `other * self` as an Fsum. |
__round__(self, ndigits=None) Not implemented. |
__rpow__(self, other, *mod) Return `other ** self` as an Fsum. |
__rsub__(self, other) Return `other - self` as Fsum. |
__rtruediv__(self, other) Return `other / self` as an Fsum. |
int |
__sizeof__(self) Return the size of this instance in `bytes`. |
__str__(self) Return the default `str(this)`. |
__sub__(self, other) Return `self - other` as an Fsum. |
__truediv__(self, other) Return `self / other` as an Fsum. |
__trunc__(self) Return this instance as an `int`. |
__div__(self, other) Return `self / other` as an Fsum. |
__idiv__(self, other) Apply `self /= other` to this instance. |
__long__(self) Return this instance as an `int`. |
__nonzero__(self) Return `True` if this instance is non-zero. |
__rdiv__(self, other) Return `other / self` as an Fsum. |
divmod(self, other) Return `divmod(self, other)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. |
fadd(self, xs) Accumulate more scalar values from an iterable. |
fadd_(self, *xs) Accumulate more scalar values from positional arguments. |
_fadd_(self, *xs) (INTERNAL) Add all positional, known `scalar`s. |
fcopy(self, deep=False, name='') Copy this instance, `shallow` or `deep`. |
copy(self, deep=False, name='') Copy this instance, `shallow` or `deep`. |
fdiv(self, other) Apply `self /= other` to this instance. |
fdivmod(self, other) Return `divmod(self, other)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. |
fmul(self, other) Apply `self *= other` to this instance. |
fpow(self, other, *mod) Apply `self **= other` to this instance. |
fsub(self, xs) Subtract several values. |
fsub_(self, *xs) Subtract any positional value. |
fsum(self, xs=None) Add several values or `None` and sum all. |
fsum_(self, *xs) Add any positional value and sum all. |
fsum2(self, xs=None) Add several values or `None` and return the running sum and the residual. |
fsum2_(self, *xs) Add any positional value and return the precision running sum and the difference. |
is_integer(self) Return `True` if this instance is an integer, `False` otherwise. |
pow(self, x) Return `self ** x` as Fsum. |
signOf(self, res=True) Determine the sign of this instance. |
toRepr(self, prec=6, sep=', ', fmt='g', **unused) Return this `Fsum` instance as representation. |
toStr(self, prec=6, sep=', ', fmt='g', **unused) Return this `Fsum` instance as string. |
Inherited from `named._Named`: `_DOT_`, `__repr__`, `attrs`, `classof`, `dup`, `rename`, `toStr2` Inherited from `object`: `__delattr__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__subclasshook__`

Properties
| ceil Get this instance' `ceil` value (`int`, except `float` in Python 2).
| floor Get this instance' `floor` (`int`, except `float` in Python 2).
| imag Return the `imaginary` part of this instance (`0.0`, always).
| partials Get this instance' partial sums (`tuple` of `float`s).
| real Return the `real` part of this instance (`float`).
Inherited from `named._Named`: `classname`, `classnaming`, `name`, `named`, `named2`, `named3`, `named4` Inherited from `object`: `__class__`

Method Details

### __init__ (self, *xs, **name_NN) (Constructor) |
New Fsum for running precision floating point summation. Arguments: `xs` - No, one or more initial values (`scalar` or Fsum instances). `name_NN` - Optional name (`str`). Overrides: object.__init__ See Also: Method Fsum.fadd.

### __add__ (self, other) (Addition operator) |
Return the sum `self + other` as an Fsum. Arguments: `other` - An Fsum or `scalar`. Returns: The sum (Fsum). See Also: Method Fsum.__iadd__.

### __ceil__ (self) |
Return this instance' `math.ceil` as `int` or `float`Fsum(. Returns: An `int`, except `float` in Python 2. See Also: Methods Fsum.__floor__ and Fsum.__int__.

### __divmod__ (self, other) |
Return `divmod(self, other)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. Returns: The quotient is `int`, except `float` in Python 2. See Also: Method Fsum.__itruediv__.

### __float__ (self) |
Return this instance as `float`, without residual. See Also: Method Fsum.fsum2.

### __floor__ (self) |
Return this instance' `math.floor` as `int` or `float`. Returns: An `int`, except `float` in Python 2. See Also: Methods Fsum.__ceil__ and Fsum.__int__.

### __floordiv__ (self, other) |
Return `self // other` as an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. Returns: The `floor` quotient (Fsum). See Also: Methods Fsum.__ifloordiv__.

### __format__ (self, *other) |
Not implemented. Overrides: object.__format__

### __hash__ (self) (Hashing function) |
Return this instance' `hash`. Overrides: object.__hash__

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

### __ifloordiv__ (self, other) |
Apply `self //= other` to this instance. Arguments: `other` - An Fsum or `scalar` divisor. Returns: This instance, updated (Fsum). Raises: `ResidualError` - Non-zero residual in `other`. `TypeError` - Invalid `other` type. `ValueError` - Zero, invalid or non-finite `other`. See Also: Methods Fsum.__itruediv__.

### __imatmul__ (self, other) |
Not implemented. Overrides: named._Named.__imatmul__

### __imod__ (self, other) |
Apply `self %= other` to this instance. Arguments: `other` - An Fsum or `scalar` divisor. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.__divmod__.

### __imul__ (self, other) |
Apply `self *= other` to this instance. Arguments: `other` - An Fsum or `scalar` factor. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.fmul.

### __int__ (self) |
Return this instance as an `int`. See Also: Methods Fsum.__ceil__ and Fsum.__floor__.

### __ipow__ (self, other, *mod) |
Apply `self **= other` to this instance. Arguments: `other` - An Fsum or `scalar` exponent. `mod` - Not implemented (`scalar`). Returns: This instance, updated (Fsum). Raises: `NotImplementedError` - Argument `mod` used. `ResidualError` - This residual non-zero and negative or fractional `other` or non-zero residual in `other`. `TypeError` - Invalid `other` type. `ValueError` - If `other` is a negative `scalar` and this instance is `0` or `other` is a fractional `scalar` and this instance is negative or has a non-zero residual or `other` is an Fsum with a non-zero residual. See Also: CPython function float_pow.

### __isub__ (self, other) |
Apply `self -= other` to this instance. Arguments: `other` - An Fsum or `scalar`. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.fadd.

### __itruediv__ (self, other) |
Apply `self /= other` to this instance. Arguments: `other` - An Fsum or `scalar` divisor. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. `ValueError` - Invalid or non-finite `other` or an `other` is an Fsum with a non-zero residual. `ZeroDivisionError` - Zero `other`. See Also: Method Fsum.__ifloordiv__.

### __matmul__ (self, other) |
Not implemented. Overrides: named._Named.__matmul__

### __mod__ (self, other) |
Return `self % other` as an Fsum. See Also: Method Fsum.__imod__.

### __mul__ (self, other) |
Return `self * other` as an Fsum. See Also: Method Fsum.__imul__.

### __pow__ (self, other, *mod) |
Return `self ** other` as an Fsum. See Also: Method Fsum.__ipow__.

### __radd__ (self, other) (Right-side addition operator) |
Return `other + self` as an Fsum. See Also: Method Fsum.__iadd__.

### __rdivmod__ (self, other) |
Return `divmod(other, self)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. Returns: The quotient is `int`, except `float` in Python 2. See Also: Method Fsum.__divmod__.

### __rfloordiv__ (self, other) |
Return `other // self` as an Fsum. See Also: Method Fsum.__ifloordiv__.

### __rmatmul__ (self, other) |
Not implemented. Overrides: named._Named.__rmatmul__

### __rmod__ (self, other) |
Return `other % self` as an Fsum. See Also: Method Fsum.__imod__.

### __rmul__ (self, other) |
Return `other * self` as an Fsum. See Also: Method Fsum.__imul__.

### __rpow__ (self, other, *mod) |
Return `other ** self` as an Fsum. See Also: Method Fsum.__ipow__.

### __rsub__ (self, other) |
Return `other - self` as Fsum. See Also: Method Fsum.__isub__.

### __rtruediv__ (self, other) |
Return `other / self` as an Fsum. See Also: Method Fsum.__itruediv__.

### __sizeof__ (self) |
Return the size of this instance in `bytes`. Returns: int Overrides: object.__sizeof__

### __str__ (self) (Informal representation operator) |
Return the default `str(this)`. Overrides: object.__str__

### __sub__ (self, other) (Subtraction operator) |
Return `self - other` as an Fsum. Arguments: `other` - An Fsum or `scalar`. Returns: The difference (Fsum). See Also: Method Fsum.__isub__.

### __truediv__ (self, other) |
Return `self / other` as an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. Returns: The quotient (Fsum). See Also: Method Fsum.__itruediv__.

### __trunc__ (self) |
Return this instance as an `int`. See Also: Methods Fsum.__ceil__ and Fsum.__floor__.

### __div__ (self, other) |
Return `self / other` as an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. Returns: The quotient (Fsum). See Also: Method Fsum.__itruediv__.

### __idiv__ (self, other) |
Apply `self /= other` to this instance. Arguments: `other` - An Fsum or `scalar` divisor. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. `ValueError` - Invalid or non-finite `other` or an `other` is an Fsum with a non-zero residual. `ZeroDivisionError` - Zero `other`. See Also: Method Fsum.__ifloordiv__.

### __long__ (self) |
Return this instance as an `int`. See Also: Methods Fsum.__ceil__ and Fsum.__floor__.

### __rdiv__ (self, other) |
Return `other / self` as an Fsum. See Also: Method Fsum.__itruediv__.

### divmod (self, other) |
Return `divmod(self, other)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. Returns: The quotient is `int`, except `float` in Python 2. See Also: Method Fsum.__itruediv__.

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

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

### fcopy (self, deep=False, name='') |
Copy this instance, `shallow` or `deep`. Arguments: `deep` - If `True` make a deep, otherwise a shallow copy (`bool`). `name` - Optional, non-empty name (`str`). Returns: The copy (Fsum).

### copy (self, deep=False, name='') |
Copy this instance, `shallow` or `deep`. Arguments: `deep` - If `True` make a deep, otherwise a shallow copy (`bool`). `name` - Optional, non-empty name (`str`). Returns: The copy (Fsum). Overrides: named._Named.copy

### fdiv (self, other) |
Apply `self /= other` to this instance. Arguments: `other` - An Fsum or `scalar` divisor. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. `ValueError` - Invalid or non-finite `other` or an `other` is an Fsum with a non-zero residual. `ZeroDivisionError` - Zero `other`. See Also: Method Fsum.__ifloordiv__.

### fdivmod (self, other) |
Return `divmod(self, other)` as 2-tuple `(quotient, remainder)`, an `int` or `float` and an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. Returns: The quotient is `int`, except `float` in Python 2. See Also: Method Fsum.__itruediv__.

### fmul (self, other) |
Apply `self *= other` to this instance. Arguments: `other` - An Fsum or `scalar` factor. Returns: This instance, updated (Fsum). Raises: `TypeError` - Invalid `other` type. See Also: Method Fsum.fmul.

### fpow (self, other, *mod) |
Apply `self **= other` to this instance. Arguments: `other` - An Fsum or `scalar` exponent. `mod` - Not implemented (`scalar`). Returns: This instance, updated (Fsum). Raises: `NotImplementedError` - Argument `mod` used. `ResidualError` - This residual non-zero and negative or fractional `other` or non-zero residual in `other`. `TypeError` - Invalid `other` type. `ValueError` - If `other` is a negative `scalar` and this instance is `0` or `other` is a fractional `scalar` and this instance is negative or has a non-zero residual or `other` is an Fsum with a non-zero residual. See Also: CPython function float_pow.

### fsub (self, xs) |
Subtract several values. Arguments: `xs` - Iterable, list, tuple. etc. (`scalar` or Fsum instances). Returns: This instance, updated (Fsum). See Also: Method Fsum.fadd.

### fsub_ (self, *xs) |
Subtract any positional value. Arguments: `xs` - Values to subtract (`scalar` or Fsum instances), all positional. Returns: This instance, updated (Fsum). See Also: Method Fsum.fadd.

### fsum (self, xs=None) |
Add several values or `None` and sum all. Arguments: `xs` - Iterable, list, tuple, etc. (`scalar` or Fsum instances). Returns: Precision running sum (`float`). Raises: `OverflowError` - Partial `2sum` overflow. `TypeError` - Non-scalar `xs` value. `ValueError` - Invalid or non-finite `xs` value. Note: Accumulation can continue after summation.

### fsum_ (self, *xs) |
Add any positional value and sum all. Arguments: `xs` - Values to add (`scalar` or Fsum instances), all positional. Returns: Precision running sum (`float`). See Also: Method Fsum.fsum.

### fsum2 (self, xs=None) |
Add several values or `None` and return the running sum and the residual. Arguments: `xs` - Iterable, list, tuple, etc. (`scalar` or Fsum instances). Returns: Fsum2Tuple`(fsum, residual)` with the running `fsum` and the `residual`, the sum of the remaining `partials`. See Also: Methods Fsum.fsum and Fsum.fsum2_

### fsum2_ (self, *xs) |
Add any positional value and return the precision running sum and the difference. Arguments: `xs` - Values to add (`scalar` or Fsum instances), all positional. Returns: 2-Tuple `(sum, delta)` with the precision running `sum` and the difference `delta` with the prior running `sum` (`float`s). See Also: Method Fsum.fsum_.

### pow (self, x) |
Return `self ** x` as Fsum. Arguments: `x` - The exponent (`scalar` or Fsum instance). Returns: The `pow(self, x)` (Fsum). Raises: `ResidualError` - This residual non-zero and negative or fractional `x`. `TypeError` - Non-scalar `x`. `ValueError` - Invalid or non-finite `factor`. See Also: Method Fsum.__ipow__.

### signOf (self, res=True) |
Determine the sign of this instance. Arguments: `res` - If `True` include the residual, otherwise ignore (`bool`). Returns: The sign (`int`, -1, 0 or +1).

### toRepr (self, prec=6, sep=', ', fmt='g', **unused) |
Return this `Fsum` instance as representation. Arguments: `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped for `prec` values of 1 and above, but kept for negative `prec` values. `sep` - Optional separator to join (`str`). `fmt` - Optional, `float` format (`str`). Returns: This instance (`str`). Overrides: named._Named.toRepr

### toStr (self, prec=6, sep=', ', fmt='g', **unused) |
Return this `Fsum` instance as string. Arguments: `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped for `prec` values of 1 and above, but kept for negative `prec` values. `sep` - Optional separator to join (`str`). `fmt` - Optional, `float` format (`str`). Returns: This instance (`repr`). Overrides: named._Named.toStr

Property Details

### ceil Get this instance' `ceil` value (`int`, except `float` in Python 2). Get method: ceil(self) - Get this instance' `ceil` value (`int`, except `float` in Python 2). Set method: _fset_error(inst, val) - Throws an `AttributeError`, always. Delete Method: _fdel(inst) - Zap the cached/memoized `property` value. See Also: Read-only properties Fsum.floor, Fsum.imag and Fsum.real.

### floor Get this instance' `floor` (`int`, except `float` in Python 2). Get method: floor(self) - Get this instance' `floor` (`int`, except `float` in Python 2). Set method: _fset_error(inst, val) - Throws an `AttributeError`, always. Delete Method: _fdel(inst) - Zap the cached/memoized `property` value. See Also: Read-only properties Fsum.ceil, Fsum.imag and Fsum.real.

### imag Return the `imaginary` part of this instance (`0.0`, always). Get method: imag(self) - Return the `imaginary` part of this instance (`0.0`, always). Set method: _fset_error(inst, val) - Throws an `AttributeError`, always. Delete Method: _fdel(inst) - Zap the cached/memoized `property` value. See Also: Read-only properties Fsum.ceil, Fsum.floor and Fsum.real.

### partials Get this instance' partial sums (`tuple` of `float`s). Get method: partials(self) - Get this instance' partial sums (`tuple` of `float`s). Set method: _fset_error(inst, val) - Throws an `AttributeError`, always. Delete Method: _fdel(inst) - Zap the cached/memoized `property` value.

### real Return the `real` part of this instance (`float`). Get method: real(self) - Return the `real` part of this instance (`float`). Set method: _fset_error(inst, val) - Throws an `AttributeError`, always. Delete Method: _fdel(inst) - Zap the cached/memoized `property` value. See Also: Method Fsum.__float__ and read-only properties Fsum.ceil, Fsum.floor and Fsum.imag.