Matrix-by-matrix product in TT1.0 format [RES]=TT_MM(MAT1,MAT2) Matrix MAT1 by matrix MAT2 product in the TT-format. Please avoid its usage: it will be removed in future releases. Use * operator from the object-oriented version. TT-Toolbox 2.2, 2009-2011 This is TT Toolbox, written by Ivan Oseledets, Olga Lebedeva 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 [res]=tt_mm(mat1,mat2) 0002 %Matrix-by-matrix product in TT1.0 format 0003 % [RES]=TT_MM(MAT1,MAT2) Matrix MAT1 by matrix MAT2 product in the 0004 % TT-format. Please avoid its usage: it will be removed in 0005 % future releases. Use * operator from the object-oriented version. 0006 % 0007 % 0008 % TT-Toolbox 2.2, 2009-2011 0009 % 0010 %This is TT Toolbox, written by Ivan Oseledets, Olga Lebedeva 0011 %Institute of Numerical Mathematics, Moscow, Russia 0012 %webpage: http://spring.inm.ras.ru/osel 0013 % 0014 %For all questions, bugs and suggestions please mail 0015 %ivan.oseledets@gmail.com 0016 %--------------------------- 0017 d=size(mat1,1); 0018 res=cell(d,1); 0019 k=1; 0020 for s=1:2 0021 n1=size(mat1{k},1); 0022 m1=size(mat1{k},2); 0023 rm=size(mat1{k},3); 0024 n2=size(mat2{k},1); 0025 m2=size(mat2{k},2); 0026 rv=size(mat2{k},3); 0027 %mat1{1} is (n1 x m1 x rm , mat2{1} is n2xm2xrm, result is n1xm2xrv1*rv) 0028 %res{1}=reshape(permute(mat1{1},[1,3,2],[n1*rm1]),m1)*reshape(mat2{1},[n2,m2*rv2]); 0029 res{k}=reshape(permute(mat1{k},[1,3,2]),[n1*rm,m1])*reshape(mat2{k},[n2,m2*rv]); 0030 %res{1} is n1 x rm x m2 x rv 0031 res{k}=reshape(res{k},[n1,rm,m2,rv]); 0032 res{k}=permute(res{k},[1,3,2,4]); 0033 res{k}=reshape(res{k},[n1,m2,rm*rv]); 0034 if ( k == 1 ) 0035 k=d; 0036 end 0037 end 0038 for i=2:d-1 0039 n1=size(mat1{i},1); 0040 m1=size(mat1{i},2); 0041 rm1=size(mat1{i},3); 0042 rm2=size(mat1{i},4); 0043 n2=size(mat2{i},1); 0044 m2=size(mat2{i},2); 0045 rv1=size(mat2{i},3); 0046 rv2=size(mat2{i},4); 0047 %mat1{i} is n1 x m1 x rm1 x rm2 0048 %mat2{i} is n2 x m2 x rv1 x rv2 0049 %n1 x rm1 x rm2 x m1 * n2 x m2 x rv1 x rv2 0050 %n1 x rm1 x rm2 x m2 x rv1 x rv2 0051 %Need: n1 x m2 x rm1 x rv1 x rm2 x rv2 0052 %Permut: 1 4 2 5 3 6 0053 res{i}=reshape(permute(mat1{i},[1,3,4,2]),[n1*rm1*rm2,m1])*reshape(mat2{i},[n2,m2*rv1*rv2]); 0054 res{i}=reshape(res{i},[n1,rm1,rm2,m2,rv1,rv2]); 0055 res{i}=permute(res{i},[1,4,2,5,3,6]); 0056 res{i}=reshape(res{i},[n1,m2,rm1*rv1,rm2*rv2]); 0057 end 0058 return 0059 end