Removes singleton dimensions from the TT-tensor [TT]=TT_SQUEEZE(TT) Removes singleton dimensions from the TT-tensor. Uses TT1.0 format. Please avoid its usage: it will be removed in future releases. Use reshape() and squeeze() from the object-oriented version 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]=tt_squeeze(tt) 0002 %Removes singleton dimensions from the TT-tensor 0003 % [TT]=TT_SQUEEZE(TT) Removes singleton dimensions from the TT-tensor. 0004 % Uses TT1.0 format. Please avoid its usage: it will be removed in 0005 % future releases. Use reshape() and squeeze() from the object-oriented 0006 % version 0007 % 0008 % 0009 % TT-Toolbox 2.2, 2009-2012 0010 % 0011 %This is TT Toolbox, written by Ivan Oseledets et al. 0012 %Institute of Numerical Mathematics, Moscow, Russia 0013 %webpage: http://spring.inm.ras.ru/osel 0014 % 0015 %For all questions, bugs and suggestions please mail 0016 %ivan.oseledets@gmail.com 0017 %--------------------------- 0018 0019 % 0020 % If a singleton dimension is in the middle of a train - everything breakes 0021 % Use tt_reshape instead! 0022 0023 d=size(tt,1); 0024 k=1; 0025 while ( k <= d ) 0026 if (size(tt{k},1) == 1 ) %Singleton dimension 0027 if ( k == 1 ) %Singleton dimension is the first one 0028 vec=tt{k}; r=size(vec,2); vec=reshape(vec,[1,r]); 0029 tt{k+1}=ten_conv(tt{k+1},2,vec'); 0030 n=size(tt{k+1},1); r=size(tt{k+1},3); 0031 tt{k+1}=reshape(tt{k+1},[n,r]); 0032 tt{k}=[]; 0033 else 0034 %Delete the dimension k (and incorporate into the 0035 %k-1) 0036 mat=tt{k}; r1=size(mat,2); r2=size(mat,3); 0037 mat=reshape(mat,[r1,r2]); 0038 tt{k-1}=ten_conv(tt{k-1},3,mat); 0039 tt(k)=[]; 0040 d=d-1; 0041 end 0042 else 0043 k=k+1; 0044 end 0045 end 0046 return 0047 end