Constructs diagonal TT-matrix from TT-tensor [TM]=DIAG(TT) constructs diagonal TT-matrix from TT-tensor 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 [tm]=diag(tt) 0002 %Constructs diagonal TT-matrix from TT-tensor 0003 % 0004 % [TM]=DIAG(TT) constructs diagonal TT-matrix from TT-tensor 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 d=tt.d; 0018 n=tt.n; 0019 r=tt.r; 0020 cr=tt.core; 0021 ps=tt.ps; 0022 psm=cumsum([1;(n.^2).*r(1:d).*r(2:d+1)]); 0023 crm=zeros(psm(d+1)-1,1); 0024 for i=1:d 0025 cr1=cr(ps(i):ps(i+1)-1); cr1=reshape(cr1,[r(i),n(i),r(i+1)]); 0026 crm1=zeros(r(i),n(i),n(i),r(i+1)); 0027 for s1=1:r(i) 0028 for s2=1:r(i+1) 0029 dd=cr1(s1,:,s2); 0030 dd=reshape(dd,[n(i),1]); 0031 crm1(s1,:,:,s2)=diag(dd); 0032 end 0033 end 0034 crm(psm(i):psm(i+1)-1)=crm1(:); 0035 end 0036 tt.ps=psm; 0037 tt.core=crm; 0038 tt.n=n.^2; 0039 tm=tt_matrix; 0040 tm.m=n; 0041 tm.n=n; 0042 tm.tt=tt; 0043 return 0044 end