TuckerTensorTrain.resize#

t3toolbox.tucker_tensor_train.TuckerTensorTrain.resize(new_shape, new_tucker_ranks, new_tt_ranks, sharing=None)#
def resize(
        self,
        new_shape: Sequence[int], # len=d
        new_tucker_ranks: Sequence[int], # len=d
        new_tt_ranks: Sequence[int], # len=d+1
        sharing: typ.Sequence = None, # len=d; group labels (None = unshared)
) -> 'TuckerTensorTrain':

Change shape and ranks by resizing cores. Makes cores bigger via zero padding. Makes cores smaller via truncation.

With sharing, the resized group factors stay SHARED – one array assigned to every group mode (the input’s factors must already be tied; safe mode checks). This is the zero-padded warm start of shared rank continuation: pad the group factor once, same array at every mode.

Returns:

Tucker tensor train with cores resized so that shape=new_shape, tucker_ranks=new_tucker_ranks, tt_ranks=new_tt_ranks.

Return type:

TuckerTensorTrain

Parameters:
  • new_shape (collections.abc.Sequence[int])

  • new_tucker_ranks (collections.abc.Sequence[int])

  • new_tt_ranks (collections.abc.Sequence[int])

  • sharing (Sequence)

Examples

>>> import numpy as np
>>> import t3toolbox.tucker_tensor_train as t3
>>> x = t3.TuckerTensorTrain.randn((14,15,16), (4,6,5), (1,3,2,1))
>>> padded_x = x.resize((17,18,17), (8,8,8), (1,5,6,1))
>>> print(padded_x.structure)
((17, 18, 17), (8, 8, 8), (1, 5, 6, 1), ())

Example where first and last ranks are nonzero:

>>> import numpy as np
>>> import t3toolbox.tucker_tensor_train as t3
>>> x = t3.TuckerTensorTrain.randn((14,15,16), (4,6,5), (3,3,2,4))
>>> padded_x = x.resize((17,18,17), (8,8,8), (5,5,6,7))
>>> print(padded_x.structure)
((17, 18, 17), (8, 8, 8), (5, 5, 6, 7), ())

Shared factors: a plain resize pads each mode separately (tied VALUES, separate arrays); sharing= keeps the group factor one object – and the represented tensor unchanged:

>>> np.random.seed(0)
>>> xs = t3.TuckerTensorTrain.randn((5, 5, 4), (2, 2, 2), (1, 2, 2, 1)).share((0, 0, 1),
...                                                                           max_tucker_ranks=2)
>>> xp = xs.resize(xs.shape, (3, 3, 2), (1, 2, 2, 1), sharing=(0, 0, 1))
>>> print(xp.tucker_cores[0] is xp.tucker_cores[1],
...       bool(np.allclose(xp.to_dense(), xs.to_dense())))
True True