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

# Class Fsum

      object --+
               |
    named._Named --+
                   |
                  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, **name) Initialize a new accumulator with one or more start values. |
__abs__(self) Return absolute value of this instance. |
__add__(self, other) Sum of this and a scalar or an other instance. |
__bool__(self) Is this instance non-zero?. |
__ceil__(self) Return the `ceil` of this instance as `float`. |
__divmod__(self, other) Return the 2-tuple `divmod(this_instance, other)`. |
__eq__(self, other) Compare this and an other instance or scalar. |
__float__(self) Convert this instance to `float` as `float(self.fsum())`. |
__floor__(self) Return the `floor` of this instance as `float`. |
__floordiv__(self, other) Not implemented. |
__format__(self, *other) Not implemented. |
__ge__(self, other) Compare this and an other instance or scalar. |
__gt__(self, other) Compare this and an other instance or scalar. |
__hash__(self) Return the `hash` of this instance. |
__iadd__(self, other) Add a scalar or an other instance to this instance. |
__int__(self) Convert this instance to `int` as `int(self.fsum() + partials)`. |
__imatmul__(self, other) Not implemented. |
__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. |
__itruediv__(self, other) Devide this instance by a scalar divisor only. |
__le__(self, other) Compare this and an other instance or scalar. |
__len__(self) Return the total number of accumulated values (`int`). |
__lt__(self, other) Compare this and an other instance or scalar. |
__matmul__(self, other) Not implemented. |
__mod__(self, other) Return `this_instance % other`. |
__mul__(self, other) Product of this and an other instance or a scalar. |
__ne__(self, other) Compare this and 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) Not implemented. |
__radd__(self, other) Not implemented. |
__rdivmod__(self, other) Not implemented. |
__rfloordiv__(self, other) Not implemented. |
__rmatmul__(self, other) Not implemented. |
__rmod__(self, other) Not implemented. |
__rmul__(self, other) Not implemented. |
__round__(self, ndigits=None) Not implemented. |
__rpow__(self, other, *mod) Not implemented. |
__rsub__(self, other) Not implemented. |
__rtruediv__(self, other) Not implemented. |
int |
__sizeof__(self) Size of this instance in `bytes`. |
__str__(self) Default `str(self)`. |
__sub__(self, other) Difference of this and an other instance or a scalar. |
__truediv__(self, other) Quotient of this instance and a scalar. |
__trunc__(self) Convert this instance to `int` as `int(self.fsum() + partials)`. |
__div__(self, other) Quotient of this instance and a scalar. |
__idiv__(self, other) Devide this instance by a scalar divisor only. |
__long__(self) Convert this instance to `int` as `int(self.fsum() + partials)`. |
__nonzero__(self) Is this instance non-zero?. |
fadd(self, xs) Accumulate more scalar values from an iterable. |
fadd_(self, *xs) Accumulate more scalar values from positional arguments. |
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. |
fsub(self, iterable) Subtract more scalar values from an iterable. |
fsub_(self, *xs) Subtract more scalar values from positional arguments. |
fsum(self, iterable=`(``)`) Accumulate more scalar values from an iterable and sum all. |
fsum_(self, *xs) Accumulate more scalar values from positional arguments and sum all. |
fsum2_(self, *xs) Accumulate more scalar values from positional arguments, sum all and provide the sum and delta. |
is_integer(self) Return `True` if this instance is an integer. |
Inherited from `named._Named`: `_DOT_`, `__repr__`, `attrs`, `classof`, `dup`, `rename`, `toRepr`, `toStr`, `toStr2` Inherited from `object`: `__delattr__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__subclasshook__`

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

Properties
| imag Return the imaginary part of this instance.
| real Return the real part of this instance.
Inherited from `named._Named`: `classname`, `classnaming`, `name`, `named`, `named2`, `named3`, `named4` Inherited from `object`: `__class__`

Method Details

### __init__ (self, *starts, **name) (Constructor) |
Initialize a new accumulator with one or more start values. Arguments: `starts` - No, one or more start values (`scalar`s). `name` - Optional name (`str`). 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 a scalar or an other instance. Arguments: `other` - Fsum instance or `scalar`. Returns: The sum (Fsum). See Also: Method Fsum.__iadd__.

### __ceil__ (self) |
Return the `ceil` of this instance as `float`. See Also: Methods __floor__ and __int__.

### __divmod__ (self, other) |
Return the 2-tuple `divmod(this_instance, other)`. See Also: Method __itruediv__.

### __floor__ (self) |
Return the `floor` of this instance as `float`. See Also: Methods __ceil__ and __int__.

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

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

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

### __int__ (self) |
Convert this instance to `int` as `int(self.fsum() + partials)`. See Also: Methods __ceil__ and __floor__.

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

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

### __itruediv__ (self, other) |
Devide this instance by a scalar divisor only. Arguments: `other` - The denominator (`scalar`). Returns: This instance (Fsum). Raises: `TypeError` - Non-scalar `other`. `ValueError` - Zero, invalid or non-finite `other` or an Fsum `other` with too many `partials`.

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

### __mod__ (self, other) |
Return `this_instance % other`. See Also: Method __divmod__.

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

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

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

### __str__ (self) (Informal representation operator) |
Default `str(self)`. 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 (Fsum). See Also: Method Fsum.__isub__.

### __truediv__ (self, other) |
Quotient of this instance and a scalar. Arguments: `other` - The denominator (`scalar`). Returns: The quotient (Fsum). Raises: `TypeError` - Non-scalar `other`. `ValueError` - Zero, invalid or non-finite `other` or an Fsum `other` with too many `partials`.

### __trunc__ (self) |
Convert this instance to `int` as `int(self.fsum() + partials)`. See Also: Methods __ceil__ and __floor__.

### __div__ (self, other) |
Quotient of this instance and a scalar. Arguments: `other` - The denominator (`scalar`). Returns: The quotient (Fsum). Raises: `TypeError` - Non-scalar `other`. `ValueError` - Zero, invalid or non-finite `other` or an Fsum `other` with too many `partials`.

### __idiv__ (self, other) |
Devide this instance by a scalar divisor only. Arguments: `other` - The denominator (`scalar`). Returns: This instance (Fsum). Raises: `TypeError` - Non-scalar `other`. `ValueError` - Zero, invalid or non-finite `other` or an Fsum `other` with too many `partials`.

### __long__ (self) |
Convert this instance to `int` as `int(self.fsum() + partials)`. See Also: Methods __ceil__ and __floor__.

### 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 (Fsum). Raises: `TypeError` - Non-scalar `factor`. `ValueError` - Invalid or non-finite `factor`. See Also: Method Fsum.fadd.

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

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

### fsum (self, iterable=`(``)`) |
Accumulate more scalar 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 scalar 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 scalar 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.

Property Details

### imag Return the imaginary part of this instance. Get method: imag(self) - Return the imaginary part of this instance. 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. Get method: real(self) - Return the real part of this instance. Set method: _fset_error(inst, val) - Throws an `AttributeError`, always. Delete Method: _fdel(inst) - Zap the cached/memoized `property` value.