Linear Combinations

class pybs.utils.linearCombination.LinearCombination(iterable=None, *args, **kwds)[source]

Class to represent linear combinations of arbitrary elements.

__setitem__(key, value)[source]

Called when coefficients are set as e.g. linComb[elem]=4.

Ensures the coefficient is a Number, and that the key is deleted if the coefficient is 0.

__missing__(key)[source]

Called if an element is not in the LinearCombination.

If an element is not in the LinearCombination, its coefficient is 0.

__iadd__(other)[source]

Overload inplace addition (self += other).

If other is a LinearCombination, they are added as vectors, if not other is assumed to be an element and is bumped by 1.

__add__(other)[source]

Overload addition (self + other).

Same rule as above if other is not LinearCombination.

__isub__(other)[source]

Overload inplace subtraction (self -= other).

Same rule as above if other is not LinearCombination.

__sub__(other)[source]

Overload subtraction (self - other).

Same rule as above if other is not LinearCombination.

__mul__(other)[source]

Overload multiplication, used for scalar multiplication (self * num).

__rmul__(other)[source]

Overload multiplication to deal with scalar multiplication from the right (num * self).

dimensions()[source]

Number of different elements in the multiset.

copy()[source]

Return an identical LinearCombination.

__delitem__(elem)[source]

Like dict.__delitem__() but does not raise KeyError for missing values.