TuckerTensorTrain.unstack#
- t3toolbox.tucker_tensor_train.TuckerTensorTrain.unstack()#
def unstack(self): # returns an array-like structure of nested tuples containing TuckerTensorTrains
If this object contains multiple stacked T3s, this unstacks them into an array-like tree of nested tuples with the same “tree shape” as self.stack_shape.
- Returns:
Unstacked TuckerTensorTrain.
- Return type:
Array-like tree of nested tuples with TuckerTensorTrain leafs
Examples
>>> import numpy as np >>> import t3toolbox.tucker_tensor_train as t3 >>> np.random.seed(0) >>> x = t3.TuckerTensorTrain.randn((14,15,16), (4,5,6), (1,3,2,1), stack_shape=(3,5)) >>> unstacked_x = x.unstack() >>> print([len(s) for s in unstacked_x]) # nested tuples mirror stack_shape=(3,5) [5, 5, 5] >>> tucker13 = tuple([B[1,3] for B in x.tucker_cores]) # build slice (1,3) by hand >>> tt13 = tuple([G[1,3] for G in x.tt_cores]) >>> x13 = t3.TuckerTensorTrain(tucker13, tt13) >>> print(bool((x13 - unstacked_x[1][3]).norm() < 1e-11)) # matches unstacked leaf [1][3] True