httk.core.vectors.mutablefracvector¶
A mutable, list-backed variant of FracVector.
Classes¶
Same as |
Module Contents¶
- class httk.core.vectors.mutablefracvector.MutableFracVector(values, *, denom=None, simplify=False, chain=False, min_accuracy=fractions.Fraction(1, 10000))¶
Bases:
httk.core.vectors.fracvector.FracVectorBaseSame as
FracVector, only this version allows 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.
- Parameters:
values (Any) – A rational value-like to convert, such as nested sequences or scalars.
denom (int | None) – An optional additional common denominator.
simplify (bool) – Whether to reduce the resulting denominator.
chain (bool) – Whether to flatten the outermost nested sequence.
min_accuracy (fractions.Fraction | None) – Minimum accuracy for decimal values, or
Nonefor exact conversion.
Methods with
set_*prefixes perform 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.
- nested_map: ClassVar[collections.abc.Callable[Ellipsis, Any]]¶
- nested_inmap: ClassVar[collections.abc.Callable[Ellipsis, Any]]¶
- nested_map_fractions: ClassVar[collections.abc.Callable[Ellipsis, Any]]¶
- noms: Any¶
- validate()¶
Return whether the vector’s stored list structure is valid.
- invalidate()¶
Internal method to call when the MutableFracVector is changed in such a way that cached properties are invalidated (e.g.,
_dim).- Returns:
None.
- Return type:
None
- set_negative()¶
Change the MutableFracVector inline into its own negative:
self -> -self.
- set_T()¶
Change the MutableFracVector inline into its own transpose:
self -> self.T.
- set_inv()¶
Change the MutableFracVector inline into its own inverse:
self -> self^-1.- Returns:
The inverse scalar when
selfis scalar; otherwiseNoneafter mutation.- Return type:
Any
- set_simplify()¶
Change the MutableFracVector; reduces any common factor between the denominator and all nominators.
- set_set_denominator(resolution=1000000000)¶
Change the MutableFracVector; reduces resolution.
- Parameters:
resolution (int) – The new denominator; each element becomes the closest numerical approximation using this denominator.
- set_normalize()¶
Add/remove an integer +/-N to each element to place it in the range [0, 1).
- set_normalize_half()¶
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()