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

Class Fsum

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

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 divmod(this_instance, other) as 2-tuple (quotient, remainder) both float.
 
__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.
 
__imatmul__(self, other)
Not implemented.
 
__imul__(self, other)
Multiply this instance by a scalar or an other instance.
 
__int__(self)
Convert this instance to int as int(self.fsum() + partials).
 
__ipow__(self, other, *mod)
Raise this instance to power other.
 
__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)
Return self ** other as Fsum, see Fsum.__ipow__.
 
__radd__(self, other)
Sum of this and a scalar or an other instance.
 
__rdivmod__(self, other)
Not implemented.
 
__rfloordiv__(self, other)
Not implemented.
 
__rmatmul__(self, other)
Not implemented.
 
__rmod__(self, other)
Return other % self as Fsum.
 
__rmul__(self, other)
Product of this and an other instance or a scalar.
 
__round__(self, ndigits=None)
Not implemented.
 
__rpow__(self, other, *mod)
Not implemented.
 
__rsub__(self, other)
Return other - this as Fsum.
 
__rtruediv__(self, other)
Return other / self as Fsum.
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, xs)
Subtract several scalar values.
 
fsub_(self, *xs)
Subtract all scalar positional values.
 
fsum(self, xs=None)
Accumulate more scalar values and sum all.
 
fsum_(self, *xs)
Accumulate all scalar positional values and sum all.
 
fsum2(self, xs=None)
Accumulate more scalar values and return the sum and residual.
 
fsum2_(self, *xs)
Accumulate all scalar positional values and provide the sum and delta.
 
is_integer(self)
Return True if this instance is an integer.
 
toRepr(self, prec=8, sep=', ', fmt='g', **unused)
Return this Fsum instance as representation.
 
toStr(self, prec=8, 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__

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 (scalars).
  • 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 divmod(this_instance, other) as 2-tuple (quotient, remainder) both float.

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.

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

__int__ (self)

 

Convert this instance to int as int(self.fsum() + partials).

See Also: Methods __ceil__ and __floor__.

__ipow__ (self, other, *mod)

 

Raise this instance to power other.

Arguments:
  • other - The exponent (scalar).
  • mod - Not implemented (scalar).
Returns:
This instance, updated (Fsum).
Raises:
  • NotImplementedError - Argument mod used.
  • TypeError - Non-scalar other.
  • ValueError - Fractional other and this instance is negative or has a non-zero residual or negative other and this instance 0.

See Also: CPython function float_pow.

__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, updated (Fsum).
Raises:
  • TypeError - Non-scalar other.
  • ValueError - Zero, invalid or non-finite other or an Fsum other with non-zero partials.
  • ZerDivisionError - Zero other.

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

__radd__ (self, other)
(Right-side 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__.

__rmatmul__ (self, other)

 

Not implemented.

Overrides: named._Named.__rmatmul__

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

__sizeof__ (self)

 

Size of this instance in bytes.

Returns: int
Overrides: object.__sizeof__

__str__ (self)
(Informal representation operator)

 

Default str(self).

Overrides: object.__str__

__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, updated (Fsum).
Raises:
  • TypeError - Non-scalar other.
  • ValueError - Zero, invalid or non-finite other or an Fsum other with non-zero partials.
  • ZerDivisionError - Zero other.

__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. (scalars).
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 (scalars), 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, xs)

 

Subtract several scalar values.

Arguments:
  • xs - Iterable, list, tuple. etc. (scalars).
Returns:
This instance (Fsum).

See Also: Method Fsum.fadd.

fsub_ (self, *xs)

 

Subtract all scalar positional values.

Arguments:
  • xs - Values to subtract (scalars), all positional.
Returns:
This instance (Fsum).

See Also: Method Fsum.fadd.

fsum (self, xs=None)

 

Accumulate more scalar values and sum all.

Arguments:
  • xs - Iterable, list, tuple, etc. (scalars).
Returns:
Accurate, 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)

 

Accumulate all scalar positional values and sum all.

Arguments:
  • xs - Values to add (scalars), all positional.
Returns:
Accurate, running sum (float).

See Also: Method Fsum.fsum.

Note: Accumulation can continue after summation.

fsum2 (self, xs=None)

 

Accumulate more scalar values and return the sum and residual.

Arguments:
  • xs - Iterable, list, tuple, etc. (scalars).
Returns:
Fsum2Tuple(fsum, residual) with the accurate, running fsum and residual the precision sum of the remaining partials.

See Also: Methods Fsum.fsum and Fsum.fsum2_

fsum2_ (self, *xs)

 

Accumulate all scalar positional values and provide the sum and delta.

Arguments:
  • xs - Values to add (scalars), all positional.
Returns:
2-Tuple (sum, delta) with the accurate, running sum and the delta with the previous running sum (floats).

See Also: Method Fsum.fsum_.

Note: Accumulation can continue after summation.

toRepr (self, prec=8, 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=8, 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.

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.