MERGECORE Merging of two cores of a TT/MPS tensor. RES = MERGECORE(X, IDXL, IDXR) merges the two cores IDXL and IDXR of the TT/MPS tensor X. IDXL and IDXR must be two consecutive integers in ascending order. RES is a TT/MPS tensor of dimension X.order-1. See also SPLITCORE
0001 function res = mergecore( x, idxL, idxR ) 0002 %MERGECORE Merging of two cores of a TT/MPS tensor. 0003 % 0004 % RES = MERGECORE(X, IDXL, IDXR) merges the two cores IDXL and IDXR of 0005 % the TT/MPS tensor X. IDXL and IDXR must be two consecutive integers in 0006 % ascending order. RES is a TT/MPS tensor of dimension X.order-1. 0007 % 0008 % See also SPLITCORE 0009 0010 % TTeMPS Toolbox. 0011 % Michael Steinlechner, 2013-2016 0012 % Questions and contact: michael.steinlechner@epfl.ch 0013 % BSD 2-clause license, see LICENSE.txt 0014 0015 if ~isscalar(idxL) 0016 error('Left index IDXL must be a scalar.') 0017 end 0018 if ~isscalar(idxR) 0019 error('Right index IDXR must be a scalar.') 0020 end 0021 if diff([idxL,idxR]) ~= 1 0022 error('Choose two neighboring nodes in ascending order.') 0023 end 0024 0025 n = x.size; 0026 r = x.rank; 0027 0028 mergedcore = unfold(x.U{idxL}, 'left') * unfold(x.U{idxR}, 'right'); 0029 mergedcore = reshape( mergedcore, [r(idxL), n(idxL)*n(idxR), r(idxR+1)] ); 0030 0031 U = x.U; 0032 res = TTeMPS( {U{1:idxL-1}, mergedcore, U{idxR+1:end} } ); 0033 end 0034