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

Class Fsum

  object --+    
           |    
named._Named --+
               |
              Fsum
Known Subclasses:

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:

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.
 
as_integer_ratio(self)
Return this instance as the integer ratio.
 
__bool__(self)
Return True if this instance is non-zero.
 
__ceil__(self)
Return this instance' math.ceil as int or float.
 
__divmod__(self, other)
Return divmod(self, other) as 2-tuple (quotient, remainder), an int in Python 3+ or float in Python 2- and an Fsum.
 
__eq__(self, other)
Compare this with an other instance or scalar.
 
__float__(self)
Return this instance' current precision running sum as float or int.
 
__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 iterator 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 values 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, like float.__pos__().
 
__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).
 
__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).
 
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 scalars.
 
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 in Python 3+ or float in Python 2- 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 None or several values and sum all.
 
fsum_(self, *xs)
Add any positional value and sum all.
 
fsum2(self, xs=None)
Add None or several values and return the current precision running sum and residual.
 
fsum2_(self, *xs)
Add any positional value and return the current precision running sum and delta, the increment.
 
is_exact(self)
Is this instance' precision running fsum considered to be exact? (bool).
 
is_integer(self)
Return True if this instance is an integer, False otherwise.
 
is_math_fsum(self)
Return True if functions fsum, fsum_, fsum1 and fsum1_ are all based on Python's math.fsum, 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 in Python 3+, float in Python 2-).
  floor
Get this instance' floor (int in Python 3+, float in Python 2-).
  imag
Get the imaginary part of this instance (0.0, always).
  partials
Get this instance' current partial sums (tuple of floats).
  real
Get the real part of this instance (float).
  residual
Get this instance' residual (float or int), the sum of the partials less the precision running sum fsum.

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

as_integer_ratio (self)

 

Return this instance as the integer ratio.

Returns:
2-Tuple (numerator, denominator) both int and with denominator positive.

See Also: Standard float.as_integer_ratio in Python 3+.

__ceil__ (self)

 

Return this instance' math.ceil as int or float.

Returns:
An int in Python 3+, float in Python 2-.

See Also: Methods Fsum.__floor__ and property Fsum.ceil.

__divmod__ (self, other)

 

Return divmod(self, other) as 2-tuple (quotient, remainder), an int in Python 3+ or float in Python 2- and an Fsum.

Arguments:
  • other - An Fsum or scalar modulus.

See Also: Method Fsum.__itruediv__.

__float__ (self)

 

Return this instance' current precision running sum as float or int.

See Also: Method Fsum.fsum.

__floor__ (self)

 

Return this instance' math.floor as int or float.

Returns:
An int in Python 3+, float in Python 2-.

See Also: Methods Fsum.__ceil__ and property Fsum.floor.

__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 - Invalid or non-finite other.
  • ZeroDivisionError - Zero 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 modulus.
Returns:
This instance, updated (Fsum).

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:
  • OverflowError - Partial 2sum overflow.
  • 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 - Optional modulus (int) for the 3-argument version pow(self, other, *mod).
Returns:
This instance, updated (Fsum).
Raises:
  • OverflowError - Partial 2sum overflow.
  • ResidualError - Non-zero residual in other a negative or fractional scalar other and this instance has a non-zero residual.
  • TypeError - Invalid other type or the 3-argument pow invocation failed.
  • 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:
  • OverflowError - Partial 2sum overflow.
  • ResidualError - Non-zero residual in other.
  • TypeError - Invalid other type.
  • ValueError - Invalid or non-finite other.
  • 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).

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:
  • OverflowError - Partial 2sum overflow.
  • ResidualError - Non-zero residual in other.
  • TypeError - Invalid other type.
  • ValueError - Invalid or non-finite other.
  • 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).

Arguments:
  • other - An Fsum or scalar divisor.
Returns:
2-Tuple (quotient, remainder), with the quotient an int in Python 3+ or a float in Python 2- and the remainder an Fsum instance.

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:
  • OverflowError - Partial 2sum overflow.
  • ResidualError - Non-zero residual in other.
  • TypeError - Invalid other type.
  • ValueError - Invalid or non-finite other.
  • ZeroDivisionError - Zero other.

See Also: Method Fsum.__ifloordiv__.

fdivmod (self, other)

 

Return divmod(self, other) as 2-tuple (quotient, remainder), an int in Python 3+ or float in Python 2- and an Fsum.

Arguments:
  • other - An Fsum or scalar modulus.

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:
  • OverflowError - Partial 2sum overflow.
  • 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 - Optional modulus (int) for the 3-argument version pow(self, other, *mod).
Returns:
This instance, updated (Fsum).
Raises:
  • OverflowError - Partial 2sum overflow.
  • ResidualError - Non-zero residual in other a negative or fractional scalar other and this instance has a non-zero residual.
  • TypeError - Invalid other type or the 3-argument pow invocation failed.
  • 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 None or several values 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 None or several values and return the current precision running sum and residual.

Arguments:
  • xs - Iterable, list, tuple, etc. (scalar or Fsum instances).
Returns:
Fsum2Tuple(fsum, residual) with fsum the current precision running and 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 current precision running sum and delta, the increment.

Arguments:
  • xs - Values to add (scalar or Fsum instances), all positional.
Returns:
2-Tuple (fsum, delta) with the current precision running fsum and delta, the difference with the prior running fsum (floats).

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 consider, otherwise ignore the residual (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 in Python 3+, float in Python 2-).

Get method:
ceil(self) - Get this instance' ceil value (int in Python 3+, float in Python 2-).
Set method:
_fset_error(inst, val) - Throws an AttributeError, always.
Delete Method:
_fdel(inst) - Zap the cached/memoized property value.

Note: The ceil accounts for the residual.

See Also: Properties Fsum.floor, Fsum.imag and Fsum.real.

floor

Get this instance' floor (int in Python 3+, float in Python 2-).

Get method:
floor(self) - Get this instance' floor (int in Python 3+, float in Python 2-).
Set method:
_fset_error(inst, val) - Throws an AttributeError, always.
Delete Method:
_fdel(inst) - Zap the cached/memoized property value.

Note: The floor accounts for the residual.

See Also: Properties Fsum.ceil, Fsum.imag and Fsum.real.

imag

Get the imaginary part of this instance (0.0, always).

Get method:
imag(self) - Get 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: Properties Fsum.ceil, Fsum.floor and Fsum.real.

partials

Get this instance' current partial sums (tuple of floats).

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

real

Get the real part of this instance (float).

Get method:
real(self) - Get 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: Methods Fsum.__float__ and Fsum.fsum and properties Fsum.ceil, Fsum.floor, Fsum.imag and Fsum.residual.

residual

Get this instance' residual (float or int), the sum of the partials less the precision running sum fsum.

Get method:
residual(self) - Get this instance' residual (float or int), the sum of the partials less the precision running sum fsum.
Set method:
_fset_error(inst, val) - Throws an AttributeError, always.
Delete Method:
_fdel(inst) - Zap the cached/memoized property value.

Note: If the residual is int(0), the precision running fsum is considered to be exact.

See Also: Methods Fsum.fsum, Fsum.fsum2 and Fsum.is_exact.