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

plus

PURPOSE ^

PLUS Addition of two TT/MPS tensors.

SYNOPSIS ^

function z = plus( x, y )

DESCRIPTION ^

PLUS Addition of two TT/MPS tensors.
   Z = PLUS(X,Y) adds two TT/MPS tensors. The rank of the resulting
   tensor is 2*R.

   See also MINUS, UMINUS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function z = plus( x, y )
0002     %PLUS Addition of two TT/MPS tensors.
0003     %   Z = PLUS(X,Y) adds two TT/MPS tensors. The rank of the resulting
0004     %   tensor is 2*R.
0005     %
0006     %   See also MINUS, UMINUS.
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     % add sanity check...
0014     rx = x.rank;
0015     ry = y.rank;
0016     nx = x.size;
0017 
0018     z = TTeMPS( cell(1, x.order) );
0019         
0020     % first core:
0021     p = size(x.U{1},4);
0022     tmp = zeros( 1, nx(1), rx(2)+ry(2), p );
0023     tmp( 1, :, 1:rx(2), : ) = x.U{1};
0024     tmp( 1, :, rx(2)+1:end, : ) = y.U{1};
0025     z.U{1} = tmp;
0026 
0027     % central cores:
0028     for i = 2:x.order-1
0029         % possibility of block format:
0030         p = size(x.U{i},4);
0031         tmp = zeros( rx(i)+ry(i), nx(i), rx(i+1)+ry(i+1), p);
0032         tmp( 1:rx(i), :, 1:rx(i+1), :) = x.U{i};
0033         tmp( rx(i)+1:end, :, rx(i+1)+1:end, :) = y.U{i};
0034         z.U{i} = tmp;
0035     end
0036 
0037     % last core:
0038     p = size(x.U{end},4);
0039     tmp = zeros( rx(end-1)+ry(end-1), nx(end), 1, p );
0040     tmp( 1:rx(end-1), :, 1, : ) = x.U{end};
0041     tmp( rx(end-1)+1:end, :, 1, : ) = y.U{end};
0042     z.U{end} = tmp;
0043 end

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