tt_sketch.sketch

Interface for the streaming and orthogonal sketching algorithms

class tt_sketch.sketch.SketchedTensorTrain(sketch_: SketchContainer, left_drm: DRM, right_drm: DRM)[source]

Container for storing the output of the streaming sketch

Stores the result of the sketch as well as the DRMs used for the sketching. Can be cheaply converted to a tensor train, or the sketch can be efficiently updated using the __add__ method.

C_cores(direction='auto') List[ndarray[Any, dtype[float64]]][source]
property Omega_mats: List[ndarray[Any, dtype[float64]]]
property Psi_cores: List[ndarray[Any, dtype[float64]]]
property T: SketchedTensorTrain

Transpose of the tensor.

If a tensor has shape (n1,n2,…,nd), then transpose of the tensor has shape (nd,…,n2,n1).

dot(other: Tensor, reverse=False) float[source]

Dot product of two tensors

increase_rank(tensor: Tensor, new_left_rank: Union[int, Tuple[int, ...]], new_right_rank: Union[int, Tuple[int, ...]]) SketchedTensorTrain[source]

Increase the rank of the approximation by performing a new sketch.

Requires DRM with support for the CanIncreaseRank protocol, which currently is only supported by SparseGaussianDRM.

left_drm: DRM
property left_rank: Tuple[int, ...]
right_drm: DRM
property right_rank: Tuple[int, ...]
property size: int

Number of floating point elements used to store the tensor.

sketch_: SketchContainer
to_numpy() ndarray[Any, dtype[float64]][source]

Converts the tensor to a (dense) numpy array of same shape.

to_tt() TensorTrain[source]
tt_sketch.sketch.assemble_sketched_tt(sketch: SketchContainer, direction='auto') List[ndarray[Any, dtype[float64]]][source]

Reconstructs a TT from a sketch, using Psi and Omega matrices.

tt_sketch.sketch.blocked_stream_sketch(tensor: Tensor, left_drm: CanSlice, right_drm: CanSlice, left_rank_slices: List[Tuple[int, ...]], right_rank_slices: List[Tuple[int, ...]]) SketchContainer[source]

Do a blocked sketch.

It’s use is mainly theoretical, since this this would only be faster in a distributed setting (which isn’t properly supported).

tt_sketch.sketch.get_drm_capabilities()[source]

List what all the DRMs are capable of

tt_sketch.sketch.hmt_sketch(tensor: Tensor, rank: Union[int, Tuple[int, ...]], seed: Optional[int] = None, drm_type: Optional[Type[DRM]] = None, drm: Optional[DRM] = None, return_drm: bool = False) TensorTrain[source]

Perform an orthogonal sketch of a tensor

tt_sketch.sketch.orthogonal_sketch(tensor: Tensor, left_rank: Union[int, Tuple[int, ...]], right_rank: Union[int, Tuple[int, ...]], seed: Optional[int] = None, left_drm_type: Optional[Type[DRM]] = None, right_drm_type: Optional[Type[DRM]] = None, left_drm: Optional[DRM] = None, right_drm: Optional[DRM] = None, return_drm: bool = False) TensorTrain[source]

Perform an orthogonal sketch of a tensor

tt_sketch.sketch.stream_sketch(tensor: Tensor, left_rank: Union[int, Tuple[int, ...]], right_rank: Union[int, Tuple[int, ...]], seed: Optional[int] = None, left_drm_type: Optional[Type[DRM]] = None, right_drm_type: Optional[Type[DRM]] = None, left_drm: Optional[DRM] = None, right_drm: Optional[DRM] = None, return_drm: bool = False) SketchedTensorTrain[source]

Perform a streaming sketch of a tensor

tt_sketch.sketch_container

class tt_sketch.sketch_container.SketchContainer(Psi_cores: List[ndarray[Any, dtype[float64]]], Omega_mats: List[ndarray[Any, dtype[float64]]], shape: Optional[Tuple[int, ...]] = None, left_rank: Optional[Tuple[int, ...]] = None, right_rank: Optional[Tuple[int, ...]] = None)[source]

Container class for the Psi_cores and Omega_mats often used internally.

Omega_mats: List[ndarray[Any, dtype[float64]]]
Psi_cores: List[ndarray[Any, dtype[float64]]]
property T: SketchContainer
left_rank: Tuple[int, ...]
right_rank: Tuple[int, ...]
shape: Tuple[int, ...]
classmethod zero(shape: Tuple[int, ...], left_rank: Tuple[int, ...], right_rank: Tuple[int, ...]) SketchContainer[source]

tt_sketch.sketch_dispatch

Implements methods for dispatching sketching methods for tensors and DRMs.

class tt_sketch.sketch_dispatch.OrthogTTDRM(rank, tensor)[source]

Represents the orthogonalized TT used as left-sketch for psi

class tt_sketch.sketch_dispatch.SketchMethod(value)[source]

An enumeration.

tt_sketch.sketch_dispatch.general_sketch(tensor: Tensor, left_drm: Optional[DRM], right_drm: DRM, method: SketchMethod) SketchContainer[source]

General algorithm for sketching a tensor.

Does the heavy lifting for both the streaming and orthogonal sketching algorithms.

tt_sketch.sketch_dispatch.orth_step(Psi: ndarray[Any, dtype[float64]], Omega: Optional[ndarray[Any, dtype[float64]]]) ndarray[Any, dtype[float64]][source]

Perform the orthogonalization step in the orthogonal sketching algorithm.