Converts a canonical representation to QTT-format [TT]=CANM_TO_QTT(CAN,RMAX,EPS) Converts canonical representation CAN (Cell array of factors) of a matrix to QTT representation with accuracy parameter EPS Mode sizes should be powers of 2 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]=canm_to_qtt(can,rmax,eps) 0002 %Converts a canonical representation to QTT-format 0003 % [TT]=CANM_TO_QTT(CAN,RMAX,EPS) 0004 % Converts canonical representation CAN (Cell array of factors) 0005 % of a matrix 0006 % to QTT representation with accuracy parameter EPS 0007 % Mode sizes should be powers of 2 0008 % 0009 % 0010 % TT-Toolbox 2.2, 2009-2012 0011 % 0012 %This is TT Toolbox, written by Ivan Oseledets et al. 0013 %Institute of Numerical Mathematics, Moscow, Russia 0014 %webpage: http://spring.inm.ras.ru/osel 0015 % 0016 %For all questions, bugs and suggestions please mail 0017 %ivan.oseledets@gmail.com 0018 %--------------------------- 0019 0020 if (size(can,1) == 1 ) 0021 can=can'; 0022 end 0023 d1=size(can,1); 0024 R=size(can{1},3); 0025 d=zeros(d1,1); 0026 for i=1:d1 0027 w1=size(can{i},1); 0028 w=log2(w1); w=round(w); 0029 if (2^w ~= w1 ) 0030 fprintf('can_to_qtt error: mode %d size = %d not a power of two \n',i,w1); 0031 return 0032 end 0033 d(i)=w; 0034 end 0035 tt=tt_zeros(sum(d),4); 0036 tt_arr=cell(d1,1); 0037 for i=1:R 0038 for s=1:d1 0039 %tt_arr{s}=vec_to_nd(can{s}(:,i),eps,d(s)); 0040 tt_arr{s}=tt_mat_to_vec(full_to_nd(can{s}(:,:,i),eps,d(s))); 0041 end 0042 mat=tt_mkron(tt_arr); 0043 tt=tt_add(tt,mat); 0044 if ( tt_erank(tt) > rmax ) 0045 tt=tt_compr2(tt,eps); 0046 end 0047 end 0048 tt=tt_compr2(tt,eps); 0049 return