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.

Note: Handling of exceptions, `inf`, `INF`, `nan` and `NAN` values is different from Python's `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, **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 `float`. |
__divmod__(self, other) Return `divmod(self, other)` as 2-tuple `(quotient, remainder)` as an integer `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 `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. |
__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 Fsum. |
__radd__(self, other) Return `other + self` as an Fsum. |
__rdivmod__(self, other) Return `divmod(other, self)` as 2-tuple `(quotient, remainder)` of an integer `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. |
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 `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, divisor) Devide this instance by a scalar. |
fmul(self, factor) Multiple this instance by a scalar. |
fpow(self, x) Return a copy of this instance raised to power `x`. |
fsub(self, xs) Subtract several scalar values. |
fsub_(self, *xs) Subtract any scalar positional value. |
fsum(self, xs=None) Add more scalar values and sum all. |
fsum_(self, *xs) Add any scalar positional value and sum all. |
fsum2(self, xs=None) Add more scalar values and return the precision running sum and the residual. |
fsum2_(self, *xs) Add any scalar positional value and return the precision running sum and the difference. |
is_integer(self) Return `True` if this instance is an integer, `False` otherwise. |
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
| imag Return the `imaginary` part of this instance (`0.0`, always).
| 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, *starts, **name_NN) (Constructor) |
New Fsum for running precision floating point summation. Arguments: `starts` - No, one or more initial values (`scalar`s). `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 `float`. See Also: Methods Fsum.__floor__ and Fsum.__int__.

### __divmod__ (self, other) |
Return `divmod(self, other)` as 2-tuple `(quotient, remainder)` as an integer `float` and an Fsum. Arguments: `other` - An Fsum or `scalar` divisor. 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 `float`. 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` - Zero, invalid or non-finite `other` or an `other` is an Fsum with a non-zero residual. 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 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)` of an integer `float` and an Fsum. 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` - Zero, invalid or non-finite `other` or an `other` is an Fsum with a non-zero residual. 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__.

### fadd (self, xs) |
Accumulate more scalar values from an iterable. Arguments: `xs` - Iterable, list, tuple, etc. (`scalar`s). 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`s), 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, divisor) |
Devide this instance by a scalar. Arguments: `divisor` - The denominator (`scalar`). Returns: This instance (Fsum). Raises: `TypeError` - Non-scalar `divisor`. `ValueError` - Zero, invalid or non-finite `divisor`.

### fmul (self, factor) |
Multiple this instance by a scalar. Arguments: `factor` - The multiplier (`scalar`). Returns: This instance, updated (Fsum). Raises: `TypeError` - Non-scalar `factor`. `ValueError` - Invalid or non-finite `factor`. See Also: Method Fsum.fadd.

### fpow (self, x) |
Return a copy of this instance raised to power `x`. Arguments: `x` - The exponent (`scalar`). 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__.

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

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

### fsum (self, xs=None) |
Add more scalar values and sum all. Arguments: `xs` - Iterable, list, tuple, etc. (`scalar`s). 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 scalar positional value and sum all. Arguments: `xs` - Values to add (`scalar`s), all positional. Returns: Precision running sum (`float`). See Also: Method Fsum.fsum. Note: Accumulation can continue after summation.

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

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

### 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

### 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.

### 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__.