httk.core.vectors.mutablefracvector module

class httk.core.vectors.mutablefracvector.MutableFracVector(noms, denom)[source]

Bases: httk.core.vectors.fracvector.FracVector, httk.core.vectors.vector.MutableVector

Same as FracVector, only, this version allow assignment of elements, e.g.,

mfracvec[2,7] = 5

and, e.g.,

mfracvec[:,7] = [1,2,3,4]

Other than this, the FracVector methods exist and do the same, i.e., they return copies of the fracvector, rather than modifying it.

However, methods have also been added named with set_* prefixes which performs mutating operations, e.g.,


replaces A with its own transpose, whereas


just returns a new MutableFracVector that is the transpose of A, leaving A unmodified.

classmethod from_FracVector(other)[source]

Create a MutableFracVector from a FracVector.


Internal method to call when MutableFracVector is changed in such a way that cached properties are invalidated (e.g., _dim)

static nested_inmap(op, *ls)

Like inmap, but work for nested lists

static nested_map(op, *ls)

Map an operator over a nested list. (i.e., the same as the built-in map(), but works recursively on a nested list)

static nested_map_fractions(op, *ls)

Map an operator over a nested list, but checks every element for a method to_fractions() and uses this to further convert objects into lists of Fraction.


Changes MutableFracVector inline into own transpose: self -> self.T


Changes MutableFracVector inline into own inverse: self -> self^-1


Changes MutableFracVector inline into own negative: self -> -self


Add/remove an integer +/-N to each element to place it in the range [0,1)


Add/remove an integer +/-N to each element to place it in the range [-1/2,1/2)

This is useful to find the shortest vector C between two points A, B in a space with periodic boundary conditions [0,1):
C = (A-B).normalize_half()

Changes MutableFracVector; reduces resolution.

resolution is the new denominator, each element becomes the closest numerical approximation using this denominator.

Changes MutableFracVector; reduces any common factor between denominator and all nominators


Return a FracVector with the values of this MutableFracVector.

classmethod use(old)[source]

Make sure variable is a MutableFracVector, and if not, convert it.

httk.core.vectors.mutablefracvector.inmap(f, x)[source]

Like built-in map, but work on a list and replace the elements in the list with the result of the mapping.

httk.core.vectors.mutablefracvector.list_set_slice(l, key, values)[source]
l = list, key = python slice (i.e., what you get to __setitem__ when you write A[3:2]=[2,5]) values = a list of values,

change the elements specified by the slice in key to those given by values.

httk.core.vectors.mutablefracvector.list_slice(l, key)[source]

Given a python slice (i.e., what you get to __getitem__ when you write A[3:2]), cut out the relevant nested list.

httk.core.vectors.mutablefracvector.nested_inmap_list(op, *ls)[source]

Like inmap, but work for nested lists