Tensor by matrix multiplication over a given mode [TT]=TTM(TT,K,MAT) Multiplies TT-tensor over the K-th mode with the matrix MAT TT-Toolbox 2.2, 2009-2012 This is TT Toolbox, written by Ivan Oseledets et al. Institute of Numerical Mathematics, Moscow, Russia webpage: http://spring.inm.ras.ru/osel For all questions, bugs and suggestions please mail ivan.oseledets@gmail.com ---------------------------
0001 function [tt]=ttm(tt,k,mat) 0002 %Tensor by matrix multiplication over a given mode 0003 % [TT]=TTM(TT,K,MAT) Multiplies TT-tensor over the K-th mode 0004 % with the matrix MAT 0005 % 0006 % 0007 % TT-Toolbox 2.2, 2009-2012 0008 % 0009 %This is TT Toolbox, written by Ivan Oseledets et al. 0010 %Institute of Numerical Mathematics, Moscow, Russia 0011 %webpage: http://spring.inm.ras.ru/osel 0012 % 0013 %For all questions, bugs and suggestions please mail 0014 %ivan.oseledets@gmail.com 0015 %--------------------------- 0016 0017 cr=tt.core; 0018 if (size(cr,1) == 1) 0019 cr=cr.'; %This procedure needs "column" cr 0020 end 0021 ps=tt.ps; 0022 d=tt.d; 0023 n=tt.n; 0024 r=tt.r; 0025 m=size(mat,2); 0026 crx=cr(ps(k):ps(k+1)-1); 0027 crx=reshape(crx,[r(k),n(k),r(k+1)]); 0028 crx=permute(crx,[1,3,2]); 0029 crx=reshape(crx,[r(k)*r(k+1),n(k)]); 0030 crx=crx*mat; 0031 %crs is r(k)xr(k+1)xm 0032 crx=reshape(crx,[r(k),r(k+1),m]); 0033 crx=permute(crx,[1,3,2]); 0034 cr=[cr(1:ps(k)-1);crx(:);cr(ps(k+1):end)]; 0035 n(k)=m; 0036 tt.n=n; 0037 tt.r=r; 0038 tt.ps=cumsum([1;n.*r(1:d).*r(2:d+1)]); 0039 tt.core=cr; 0040 return 0041 end