Home > tt2 > @tt_tensor > horzcat.m

horzcat

PURPOSE ^

C=[A,B]

SYNOPSIS ^

function [c]=horzcat(a,b)

DESCRIPTION ^

C=[A,B]
   C=HORZCAT(A,B) Horizontal cat of two block-row TT-tensors
   The result has r(d+1) = sum(r(d+1,A)+r(d+1,B)). The first ranks 
   should be equal for A and B


 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 [c]=horzcat(a,b)
0002 %C=[A,B]
0003 %   C=HORZCAT(A,B) Horizontal cat of two block-row TT-tensors
0004 %   The result has r(d+1) = sum(r(d+1,A)+r(d+1,B)). The first ranks
0005 %   should be equal for A and B
0006 %
0007 %
0008 % TT-Toolbox 2.2, 2009-2012
0009 %
0010 %This is TT Toolbox, written by Ivan Oseledets et al.
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 
0018 if (isempty(b) )
0019   c=a;
0020   return
0021 elseif (isempty(a) )
0022   c=b;
0023   return
0024 end
0025 c=tt_tensor;
0026 d=a.d;
0027 ra=a.r;
0028 n=a.n;
0029 psa=a.ps;
0030 cra=a.core;
0031 rb=b.r;
0032 crb=b.core;
0033 psb=b.ps;
0034 rc=ra+rb; 
0035 if ( ra(1) == rb(1) )
0036 rc(1)=ra(1); %The only modification
0037 else
0038   error('Incorrect sizes in [A,B], please check');    
0039 end
0040 psc=cumsum([1;n.*rc(1:d).*rc(2:d+1)]);
0041 crc=zeros(1,psc(d+1)-1);
0042 
0043 %It seems: Ak
0044 %          Bk --- the first core
0045 %all others are blocks
0046 
0047 for i=1:d
0048   cr1=cra(psa(i):psa(i+1)-1);
0049   cr2=crb(psb(i):psb(i+1)-1);
0050   cr1=reshape(cr1,[ra(i),n(i),ra(i+1)]);
0051   cr2=reshape(cr2,[rb(i),n(i),rb(i+1)]);
0052   cr3=zeros(rc(i),n(i),rc(i+1));
0053   cr3(1:ra(i),:,1:ra(i+1))=cr1;
0054   cr3(rc(i)-rb(i)+1:rc(i),:,rc(i+1)-rb(i+1)+1:rc(i+1))=cr2;
0055   crc(psc(i):psc(i+1)-1)=cr3(:);
0056 end
0057 c.ps=psc;
0058 c.d=d;
0059 c.n=n;
0060 c.r=rc;
0061 c.core=crc;

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