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

A.set_T()

replaces A with its own transpose, whereas

A.T()

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.

invalidate()[source]

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.

set_T()[source]

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

set_inv()[source]

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

set_negative()[source]

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

set_normalize()[source]

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

set_normalize_half()[source]

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()
set_set_denominator(resolution=1000000000)[source]

Changes MutableFracVector; reduces resolution.

resolution is the new denominator, each element becomes the closest numerical approximation using this denominator.
set_simplify()[source]

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

to_FracVector()[source]

Return a FracVector with the values of this MutableFracVector.

classmethod use(old)[source]

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

validate()[source]
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]
Given:
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.main()[source]
httk.core.vectors.mutablefracvector.nested_inmap_list(op, *ls)[source]

Like inmap, but work for nested lists