tt_sketch.utils
- class tt_sketch.utils.MultithreadedRNG(shape, seed=None, threads=None)[source]
Multithreaded standard normal random number generator.
Copy pasta from numpy docs
- tt_sketch.utils.dematricize(A, mode, shape)[source]
Undo matricization of
Awith respect tomode. Needsshapeof original tensor.
- tt_sketch.utils.hilbert_tensor(n_dims: int, size: int) ndarray[Any, dtype[ScalarType]][source]
Create a Hilbert tensor of specified size and dimensionality.
- tt_sketch.utils.left_mul_pinv(A, B, cond=None)[source]
Compute numerically stable product
np.linalg.pinv(A)@B
- tt_sketch.utils.matricize(A: ndarray[Any, dtype[ScalarType]], mode: Union[int, Sequence[int]], mat_shape: bool = False)[source]
Matricize tensor
Awith respect tomode.If mode is an int, return matrix. If mode is a tuple, return tensor of order
len(mode)+1, unlessmat_shape=True
- tt_sketch.utils.power_decay_tensor(shape: Tuple[int], pow: float = 2.0, seed=None) Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]][source]
Create tensor of specified shape such that singular values of each unfolding decay with a power law.
- tt_sketch.utils.process_tt_rank(rank: Union[int, Tuple[int, ...]], shape: Tuple[int, ...], trim: bool) Tuple[int, ...][source]
Process TT rank, and check validity. Makes sure rank is a tuple.
If
trim=True, ranks are trimmed to the smallest possible lossless value.
- tt_sketch.utils.projector(X: ndarray[Any, dtype[ScalarType]], Y: Optional[ndarray[Any, dtype[ScalarType]]] = None) ndarray[Any, dtype[ScalarType]][source]
Compute oblique projector \(\mathcal P_{X,Y}\)
- tt_sketch.utils.right_mul_pinv(A, B, cond=None)[source]
Compute numerically stable product
A@np.linalg.pinv(B)
- tt_sketch.utils.sqrt_tensor(shape: Tuple[int, ...], a=-0.2, b=2) ndarray[Any, dtype[ScalarType]][source]
Create a tensor of specified shape with square root of a sum a grid.
Values of grid entries vary between a and b.
- tt_sketch.utils.trim_ranks(dims: Tuple[int, ...], ranks: Tuple[int, ...]) Tuple[int, ...][source]
Return TT-rank to which TT can be exactly reduced
A tt-rank can never be more than the product of the dimensions on the left or right of the rank. Furthermore, any internal edge in the TT cannot have rank higher than the product of any two connected supercores. Ranks are iteratively reduced for each edge to satisfy these two requirements until the requirements are all satisfied.