Home > tt2 > @tt_matrix > diag.m

diag

PURPOSE ^

Extract the diagonal of the TT-matrix

SYNOPSIS ^

function [tt]=diag(tm)

DESCRIPTION ^

Extract the diagonal of the TT-matrix
   [TT]=DIAG(TM) Diagonal of the TT-matrix TM as a TT-tensor TT


 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
---------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [tt]=diag(tm)
0002 %Extract the diagonal of the TT-matrix
0003 %   [TT]=DIAG(TM) Diagonal of the TT-matrix TM as a TT-tensor TT
0004 %
0005 %
0006 % TT-Toolbox 2.2, 2009-2012
0007 %
0008 %This is TT Toolbox, written by Ivan Oseledets et al.
0009 %Institute of Numerical Mathematics, Moscow, Russia
0010 %webpage: http://spring.inm.ras.ru/osel
0011 %
0012 %For all questions, bugs and suggestions please mail
0013 %ivan.oseledets@gmail.com
0014 %---------------------------
0015 tt=tt_tensor;
0016 n=tm.n;
0017 tt1=tm.tt;
0018 r=tt1.r;
0019 core=tt1.core;
0020 ps=tt1.ps;
0021 d=tt1.d;
0022 ps1=cumsum([1;n.*r(1:d).*r(2:d+1)]);
0023 core1=zeros(ps1(d+1)-1,1);
0024 for i=1:d
0025    cur_core=core(ps(i):ps(i+1)-1);cur_core=reshape(cur_core,[r(i),n(i),n(i),r(i+1)]);
0026    cur_core1=zeros(r(i),n(i),r(i+1));
0027    for j=1:n(i)
0028       cur_core1(:,j,:)=cur_core(:,j,j,:);
0029    end
0030    core1(ps1(i):ps1(i+1)-1)=cur_core1(:);
0031 end
0032 tt.r=r;
0033 tt.n=n;
0034 tt.core=core1;
0035 tt.ps=ps1;
0036 tt.d=d;
0037 return
0038 end

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005