Home > manopt > manifolds > ttfixedrank > TTeMPS_1.1 > tensorize.m

# tensorize

## PURPOSE

TENSORIZE Tensorize matrix (inverse matricization).

## SYNOPSIS

function res = tensorize( U, mode, d )

## DESCRIPTION

```TENSORIZE Tensorize matrix (inverse matricization).
X = TENSORIZE(U, MODE, D) (re-)tensorizes the matrix U along the
specified mode MODE into a tensor X of size D(1) x D(2) x D(3). Higher
dimensions than 3 are not supported. Tensorize is inverse matricization,
that is, X == tensorize( matricize(X, i), i, size(X)) for all modes i.

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

## SOURCE CODE

```0001 function res = tensorize( U, mode, d )
0002     %TENSORIZE Tensorize matrix (inverse matricization).
0003     %   X = TENSORIZE(U, MODE, D) (re-)tensorizes the matrix U along the
0004     %   specified mode MODE into a tensor X of size D(1) x D(2) x D(3). Higher
0005     %   dimensions than 3 are not supported. Tensorize is inverse matricization,
0006     %   that is, X == tensorize( matricize(X, i), i, size(X)) for all modes i.
0007     %
0008     %   See also MATRICIZE, TENSORPROD_TTEMPS, UNFOLD.
0009
0010     %   TTeMPS Toolbox.
0011     %   Michael Steinlechner, 2013-2016
0012     %   Questions and contact: michael.steinlechner@epfl.ch
0013     %   BSD 2-clause license, see LICENSE.txt
0014
0015     % pad with 1 for the last dim (annoying)
0016     if length(d) == 2
0017         d = [d, 1];
0018     end
0019
0020     switch mode
0021         case 1
0022             res = reshape( U, d );
0023         case 2
0024             res = ipermute( reshape(U, [d(2), d(1), d(3)]), [2, 1, 3] );
0025         case 3
0026             res = reshape( transpose(U), d );
0027         otherwise
0028             error('Invalid mode input in function matricize')
0029     end
0030 end```

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005