Home > manopt > manifolds > ttfixedrank > TTeMPS_1.1 > @TTeMPS > cat.m

# cat

## PURPOSE

CAT concatenation of two TT/MPS tensors.

## SYNOPSIS

function z = cat( mu, x, y )

## DESCRIPTION

```CAT concatenation of two TT/MPS tensors.
Z = CAT(MU,X,Y) concatenates two TT/MPS tensors along the
outer dimension MU.
The rank of the resulting tensor is rank(X) + rank(Y).

See also PLUS, MINUS.```

## CROSS-REFERENCE INFORMATION

This function calls: This function is called by:

## SOURCE CODE

```0001 function z = cat( mu, x, y )
0002     %CAT concatenation of two TT/MPS tensors.
0003     %   Z = CAT(MU,X,Y) concatenates two TT/MPS tensors along the
0004     %   outer dimension MU.
0005     %   The rank of the resulting tensor is rank(X) + rank(Y).
0006     %
0007     %   See also PLUS, MINUS.
0008
0009     %   TTeMPS Toolbox.
0010     %   Michael Steinlechner, 2013-2016
0011     %   Questions and contact: michael.steinlechner@epfl.ch
0012     %   BSD 2-clause license, see LICENSE.txt
0013
0014     % add sanity check...
0015     rx = x.rank;
0016     ry = y.rank;
0017     nx = x.size;
0018     ny = y.size;
0019
0020
0021     z = TTeMPS( cell(1, x.order) );
0022
0023     % first core:
0024     if mu == 1
0025         p = size(x.U{1},4); %special treatment of block TT tensors
0026         tmp = zeros( 1, nx(1)+ny(1), rx(2)+ry(2), p );
0027         tmp( 1, 1:nx(1), 1:rx(2), : ) = x.U{1};
0028         tmp( 1, nx(1)+1:end, rx(2)+1:end, : ) = y.U{1};
0029         z.U{1} = tmp;
0030     else
0031         p = size(x.U{1},4);
0032         tmp = zeros( 1, nx(1), rx(2)+ry(2), p );
0033         tmp( 1, :, 1:rx(2), : ) = x.U{1};
0034         tmp( 1, :, rx(2)+1:end, : ) = y.U{1};
0035         z.U{1} = tmp;
0036     end
0037
0038     % central cores:
0039     for i = 2:x.order-1
0040         if mu == i
0041             p = size(x.U{i},4);
0042             tmp = zeros( rx(i)+ry(i), nx(i)+ny(i), rx(i+1)+ry(i+1), p);
0043             tmp( 1:rx(i), 1:nx(i), 1:rx(i+1), :) = x.U{i};
0044             tmp( rx(i)+1:end, nx(i)+1:end, rx(i+1)+1:end, :) = y.U{i};
0045             z.U{i} = tmp;
0046         else
0047             % possibility of block format:
0048             p = size(x.U{i},4);
0049             tmp = zeros( rx(i)+ry(i), nx(i), rx(i+1)+ry(i+1), p);
0050             tmp( 1:rx(i), :, 1:rx(i+1), :) = x.U{i};
0051             tmp( rx(i)+1:end, :, rx(i+1)+1:end, :) = y.U{i};
0052             z.U{i} = tmp;
0053         end
0054     end
0055
0056     % last core:
0057     if mu == x.order
0058         p = size(x.U{end},4);
0059         tmp = zeros( rx(end-1)+ry(end-1), nx(end)+ny(end), 1, p );
0060         tmp( 1:rx(end-1), 1:nx(end), 1, : ) = x.U{end};
0061         tmp( rx(end-1)+1:end, nx(end)+1:end, 1, : ) = y.U{end};
0062         z.U{end} = tmp;
0063     else
0064         p = size(x.U{end},4);
0065         tmp = zeros( rx(end-1)+ry(end-1), nx(end), 1, p );
0066         tmp( 1:rx(end-1), :, 1, : ) = x.U{end};
0067         tmp( rx(end-1)+1:end, :, 1, : ) = y.U{end};
0068         z.U{end} = tmp;
0069     end
0070 end```

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