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

plus

PURPOSE ^

PLUS Addition of two TT/MPS block-mu tensors.

SYNOPSIS ^

function z = plus( x, y )

DESCRIPTION ^

PLUS Addition of two TT/MPS block-mu 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 block-mu 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 
0015     if ( x.mu ~= y.mu ) || ( x.p ~= y.p )
0016         error('Summands must have the same TT/MPS block-mu structure!')
0017     end
0018 
0019     rx = x.rank;
0020     ry = y.rank;
0021 
0022     z = TTeMPS_block( cell(1, x.order), x.mu, x.p );
0023         
0024     % first core:
0025     if x.mu == 1
0026         tmp = zeros( 1, x.size(1), rx(2)+ry(2), x.p );
0027         tmp( 1, :, 1:rx(2), : ) = x.U{1};
0028         tmp( 1, :, rx(2)+1:end, : ) = y.U{1};
0029     else
0030         tmp = zeros( 1, x.size(1), rx(2)+ry(2) );
0031         tmp( 1, :, 1:rx(2) ) = x.U{1};
0032         tmp( 1, :, rx(2)+1:end ) = y.U{1};
0033     end
0034     z.U{1} = tmp;
0035 
0036     % central cores:
0037     for i = 2:x.order-1
0038         % possibility of block format:
0039         if x.mu == i
0040             tmp = zeros( rx(i)+ry(i), x.size(i), rx(i+1)+ry(i+1), x.p);
0041             tmp( 1:rx(i), :, 1:rx(i+1), :) = x.U{i};
0042             tmp( rx(i)+1:end, :, rx(i+1)+1:end, :) = y.U{i};
0043         else
0044             tmp = zeros( rx(i)+ry(i), x.size(i), rx(i+1)+ry(i+1) );
0045             tmp( 1:rx(i), :, 1:rx(i+1) ) = x.U{i};
0046             tmp( rx(i)+1:end, :, rx(i+1)+1:end ) = y.U{i};
0047         end
0048         z.U{i} = tmp;
0049     end
0050 
0051     % last core:
0052     if x.mu == x.order;
0053         tmp = zeros( rx(end-1)+ry(end-1), x.size(end), 1, x.p );
0054         tmp( 1:rx(end-1), :, 1, : ) = x.U{end};
0055         tmp( rx(end-1)+1:end, :, 1, : ) = y.U{end};
0056     else
0057         tmp = zeros( rx(end-1)+ry(end-1), x.size(end) );
0058         tmp( 1:rx(end-1), : ) = x.U{end};
0059         tmp( rx(end-1)+1:end, : ) = y.U{end};
0060     end
0061     z.U{end} = tmp;
0062 end

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