0001 function res = splitcore( x, idx, nL, nR, tol )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 if ~exist('tol', 'var')
0016 tol = 1e-8;
0017 end
0018
0019 if ~isscalar(idx)
0020 error('Index IDX must be a scalar.')
0021 end
0022
0023 n = x.size;
0024 r = x.rank;
0025
0026 if nL*nR ~= n(idx)
0027 error('New sizes must be compatible with old tensor: NL*NR = X.size(idx)')
0028 end
0029
0030
0031 [U,S,V] = svd( reshape(x.U{idx}, [r(idx)*nL, nR*r(idx+1)]), 'econ');
0032 s = trunc_singular( diag(S), tol, true );
0033 U = U(:,1:s);
0034 V = V(:,1:s);
0035 S = S(1:s,1:s);
0036 newcoreR = reshape( S*V', [s, nR, r(idx+1)] );
0037 newcoreL = reshape( U, [r(idx), nL, s] );
0038
0039 C = x.U;
0040 res = TTeMPS( {C{1:idx-1}, newcoreL, newcoreR, C{idx+1:end} } );
0041 end
0042