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