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

plus

PURPOSE ^

PLUS Addition of two TT/MPS operators.

SYNOPSIS ^

function z = plus( x, y )

DESCRIPTION ^

PLUS Addition of two TT/MPS operators.
   Z = PLUS(X,Y) adds to TT/MPS operators. The resulting TT/MPS operator 
   has rank equal to the sum of the individual ranks.

   TTeMPS Toolbox. 
   Michael Steinlechner, 2013-2016
   Questions and contact: michael.steinlechner@epfl.ch
   BSD 2-clause license, see LICENSE.txt

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 operators.
0003     %   Z = PLUS(X,Y) adds to TT/MPS operators. The resulting TT/MPS operator
0004     %   has rank equal to the sum of the individual ranks.
0005     %
0006     %   TTeMPS Toolbox.
0007     %   Michael Steinlechner, 2013-2016
0008     %   Questions and contact: michael.steinlechner@epfl.ch
0009     %   BSD 2-clause license, see LICENSE.txt
0010 
0011     
0012     % add sanity check...
0013     rx = x.rank;
0014     ry = y.rank;
0015 
0016     z = TTeMPS_op( cell(1, x.order) );
0017         
0018     % first core:
0019     tmp = zeros( 1, x.size_col(1), x.size_row(1), rx(2)+ry(2) );
0020     tmp( 1, :, :, 1:rx(2) ) = x.U{1};
0021     tmp( 1, :, :, rx(2)+1:end ) = y.U{1};
0022     z.U{1} = tmp;
0023 
0024     %z.U{1} = reshape( [unfold( x.U{1}, 'left'), unfold( y.U{1}, 'left')], [1, x.size(1), x.rank(2) + y.rank(2)]);
0025 
0026     % central cores:
0027     for i = 2:x.order-1
0028         tmp = zeros( rx(i)+ry(i), x.size_col(i), x.size_row(i), rx(i+1)+ry(i+1) );
0029         tmp( 1:rx(i), :, :, 1:rx(i+1) ) = x.U{i};
0030         tmp( rx(i)+1:end, :, :, rx(i+1)+1:end ) = y.U{i};
0031         z.U{i} = tmp;
0032     end
0033 
0034     % last core:
0035     tmp = zeros( rx(end-1)+ry(end-1), x.size_col(end), x.size_row(end), 1 );
0036     tmp( 1:rx(end-1), :, :, 1 ) = x.U{end};
0037     tmp( rx(end-1)+1:end, :, :, 1 ) = y.U{end};
0038     z.U{end} = tmp;
0039 
0040     z = update_properties( z );
0041 end

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