Home > tt2 > @qtt_tucker > plus.m

plus

PURPOSE ^

A=B+C

SYNOPSIS ^

function [a]=plus(b,c)

DESCRIPTION ^

A=B+C
   [A]=PLUS(B,C) Computes the sum of two QTT-Tucker tensors B and C


 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 [a]=plus(b,c)
0002 %A=B+C
0003 %   [A]=PLUS(B,C) Computes the sum of two QTT-Tucker tensors B and C
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 if ( isempty(b) )
0016  a=c;
0017  return
0018 elseif ( isempty(c) )
0019  a=b;
0020  return
0021 end
0022 a=qtt_tucker;
0023 cb=b.core; cc=c.core;
0024 rb=rank(cb); rc=rank(cc);
0025 nb=size(cb); nc=size(cc);
0026 tb=b.tuck; tc=c.tuck;
0027 d=b.dphys;
0028 %Determine size of the result
0029 ra=rb+rc;
0030 na=nb+nc;
0031 if ( rc(1) == rb(1) )
0032     ra(1)=rb(1);
0033 else
0034   error('Inconsistent sizes in mode 1');    
0035 end
0036 if ( rc(d+1) == rb(d+1) )
0037   ra(d+1)=rb(d+1);
0038 else
0039   error('Inconsistent sizes in the last mode');    
0040 end
0041 corea=[];
0042 for i=1:d
0043   c1=cb{i}; c2=cc{i};
0044   c1=reshape(c1,[rb(i),nb(i),rb(i+1)]);
0045   c2=reshape(c2,[rc(i),nc(i),rc(i+1)]);
0046   cres=zeros(ra(i),na(i),ra(i+1));
0047   cres(1:rb(i),1:nb(i),1:rb(i+1))=c1;
0048   cres((ra(i)-rc(i)+1):ra(i),(na(i)-nc(i)+1):na(i),(ra(i+1)-rc(i+1)+1):ra(i+1))=c2;
0049   corea=[corea; cres(:)];
0050 end
0051 ca=tt_tensor; 
0052 ca.d=d;
0053 ca.n=na;
0054 ca.core=corea;
0055 ca.r=ra;
0056 ca.ps=cumsum([1;ca.n.*ca.r(1:ca.d).*ca.r(2:ca.d+1)]);
0057 ta = cell(d,1);
0058 ismatrix = 0;
0059 for i=1:d
0060    if (isa(tb{i}, 'tt_matrix'))
0061        curn = tb{i}.n;
0062        curm = tb{i}.m;
0063        tb{i} = tt_tensor(tb{i});
0064        tc{i} = tt_tensor(tc{i});
0065        ismatrix = 1;
0066    end;
0067    ta{i}=[tb{i},tc{i}];
0068    if (ismatrix)
0069        ta{i} = tt_matrix(ta{i}, curn, curm);
0070    end;
0071 end
0072 a.core=ca;
0073 a.tuck=ta;
0074 a.dphys=d;
0075 a.sz=b.sz;
0076 return
0077 end

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