Home > tt2 > @tt_tensor > kron2.m

kron2

PURPOSE ^

Computes the Pseudokronecker product of TT tensors:

SYNOPSIS ^

function [c]=kron2(a,b)

DESCRIPTION ^

 Computes the Pseudokronecker product of TT tensors:
   [C]=KRON2(A,B)
   c{i}=kron(a{i},b{i}) <- "a" indices vary faster!
   mode sizes and ranks are multiplied


 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]=kron2(a,b)
0002 % Computes the Pseudokronecker product of TT tensors:
0003 %   [C]=KRON2(A,B)
0004 %   c{i}=kron(a{i},b{i}) <- "a" indices vary faster!
0005 %   mode sizes and ranks are multiplied
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(a) )
0019   c=b;
0020   return
0021 elseif ( isempty(b) )
0022   c=a;
0023   return
0024 end
0025 if ( size(a.core,1) == 1 ) 
0026    a.core=(a.core).';
0027 end
0028 if ( size(b.core,1) == 1 ) 
0029    b.core=(b.core).';
0030 end
0031 
0032 d = a.d;
0033 if (b.d~=d)
0034     error('Could not compute kron2 from the tensors with not equal dimensions\n');
0035 end;
0036 cra = a.core;
0037 na = a.n;
0038 ra = a.r;
0039 psa = a.ps;
0040 crb = b.core;
0041 nb = b.n;
0042 rb = b.r;
0043 psb = b.ps;
0044 
0045 c=tt_tensor;
0046 n = [(na).*(nb)];
0047 r = [(ra).*(rb)];
0048 ps = cumsum([1; n.*r(2:d+1).*r(1:d)]);
0049 
0050 
0051 c.d=d;
0052 c.n=n;
0053 c.r=r;
0054 c.ps = ps;
0055 cr = zeros(ps(d+1)-1, 1);
0056 for i=1:d
0057     a1 = cra(psa(i):psa(i+1)-1);
0058     b1 = crb(psb(i):psb(i+1)-1);
0059     c1 = a1*(b1.'); % Size ra1*na*ra2, rb1*nb*rb2
0060     c1 = reshape(c1, ra(i), na(i), ra(i+1), rb(i), nb(i), rb(i+1));
0061     c1 = permute(c1, [1, 4, 2, 5, 3, 6]); % We need rc1, nc*rc2
0062     cr(ps(i):ps(i+1)-1) = c1(:);
0063 end;
0064 
0065 c.core=cr;
0066 
0067 end

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