Tt tensor#

class ivy.data_classes.factorized_tensor.tt_tensor.TTTensor(factors, inplace=False)[source]#

Bases: FactorizedTensor

__init__(factors, inplace=False)[source]#
_abc_impl = <_abc._abc_data object>#
static _tt_n_param(tensor_shape, rank)[source]#

Return the number of parameters of a MPS decomposition for a given rank and full tensor_shape.

  • tensor_shape – shape of the full tensor to decompose (or approximate)

  • rank – rank of the MPS decomposition


n_params – Number of parameters of a MPS decomposition of rank rank of a full tensor of shape tensor_shape

static index_update(tensor, indices, values)[source]#
property n_param#
static pad_tt_rank(factor_list, n_padding=1, pad_boundaries=False)[source]#

Pad the factors of a Tensor-Train so as to increase its rank without changing its reconstruction.

The tensor-train (ring) will be padded with 0s to increase its rank only but not the underlying tensor it represents.

  • factor_list – tensor list

  • n_padding (default: 1) – how much to increase the rank (bond dimension) by

  • pad_boundaries (default: False) – if True, also pad the boundaries (useful for a tensor-ring) should be False for a tensor-train to keep the boundary rank to be 1



static tt_to_tensor(factors)[source]#

Return the full tensor whose TT decomposition is given by ‘factors’.

Re-assembles ‘factors’, which represent a tensor in TT/Matrix-Product-State format into the corresponding full tensor


factors – TT factors (TT-cores)


output_tensor – tensor whose TT/MPS decomposition was given by ‘factors’

static tt_to_unfolded(factors, mode)[source]#

Return the unfolding matrix of a tensor given in TT (or Tensor- Train) format.

Reassembles a full tensor from ‘factors’ and returns its unfolding matrix with mode given by ‘mode’

  • factors – TT factors

  • mode – unfolding matrix to be computed along this mode


  • 2-D array

  • unfolding matrix at mode given by ‘mode’

static tt_to_vec(factors)[source]#

Return the tensor defined by its TT format (‘factors’) into its vectorized format.


factors – TT factors


  • 1-D array

  • vectorized format of tensor defined by ‘factors’

static validate_tt_rank(tensor_shape, rank='same', constant_rank=False, rounding='round', allow_overparametrization=True)[source]#

Return the rank of a TT Decomposition.

  • tensor_shape – shape of the tensor to decompose

  • rank (default: 'same') – way to determine the rank, by default ‘same’ if ‘same’: rank is computed to keep the number of parameters (at most) the same if float, computes a rank so as to keep rank percent of the original number of parameters if int or tuple, just returns rank

  • constant_rank (default: False) – if True, the same rank will be chosen for each modes if False (default), the rank of each mode will be proportional to the corresponding tensor_shape used only if rank == ‘same’ or 0 < rank <= 1*

  • rounding (default: 'round') – Mode for rounding One of [“round”, “floor”, “ceil”]

  • allow_overparametrization (default: True) – if False, the rank must be realizable through iterative application of SVD


rank – rank of the decomposition

static validate_tt_tensor(tt_tensor)[source]#