3.3.12. pci.api.summation module

A module with utilities for performing summation in a way that reduces numerical error

New in version 2019.

3.3.12.1. Kahan Summation

class pci.api.summation.KahanSummation(start=0)

Bases: object

Calculating the sum of many floating-point numbers has the potential to introduce numerical error.

This class is a utility to do summation in a way that reduces this numerical error using an algorithm attributed to William Kahan

Initialize this class by specifying a start value, which has a default value of 0.

This example demonstrates how to use this class.

1
2
3
4
5
6
7
from pci.api.summation import KahanSummation

k = KahanSummation()
for val in vals:
    k += val

print(k.sum)
property sum
pci.api.summation.ksum(iterable, start=0)

Utility function to perform Kahan Summation on an iterable object (e.g. list, tuple, set, etc.)