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

matricize

PURPOSE ^

MATRICIZE Matricize 3D Matlab array.

SYNOPSIS ^

function res = matricize( U, mode )

DESCRIPTION ^

MATRICIZE Matricize 3D Matlab array. 
   A = MATRICIZE(U, MODE) matricizes the 3D Matlab array U along the 
   specified mode MODE. Higher dimensions than 3 are not supported.

   See also TENSORIZE, TENSORPROD, UNFOLD.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function res = matricize( U, mode )
0002     %MATRICIZE Matricize 3D Matlab array.
0003     %   A = MATRICIZE(U, MODE) matricizes the 3D Matlab array U along the
0004     %   specified mode MODE. Higher dimensions than 3 are not supported.
0005     %
0006     %   See also TENSORIZE, TENSORPROD, UNFOLD.
0007     
0008     %   TTeMPS Toolbox.
0009     %   Michael Steinlechner, 2013-2016
0010     %   Questions and contact: michael.steinlechner@epfl.ch
0011     %   BSD 2-clause license, see LICENSE.txt
0012 
0013     d = size(U);
0014     % pad with 1 for the last dim (annoying)
0015     if length(d) == 2
0016         d = [d, 1];
0017     end
0018 
0019     switch mode
0020         case 1
0021             res = reshape( U, [d(1), d(2)*d(3)] );
0022         case 2 
0023             res = reshape( permute( U, [2, 1, 3]), [d(2), d(1)*d(3)] );
0024         case 3 
0025             res = transpose( reshape( U, [d(1)*d(2), d(3)] ) );
0026         otherwise
0027             error('Invalid mode input in function matricize')
0028     end
0029 end

Generated on Sun 05-Sep-2021 17:57:00 by m2html © 2005