Home > tt2 > @qtt_tucker > mtimes.m

mtimes

PURPOSE ^

C=A*B: Matrix-by-matrix, matrix-by-vector, matrix-by-number in QTT-Tucker

SYNOPSIS ^

function [c] = mtimes(a,b)

DESCRIPTION ^

C=A*B: Matrix-by-matrix, matrix-by-vector, matrix-by-number in QTT-Tucker
   [C]=MTIMES(A,B) Matrix multiplication for the QTT_TUCKER class


 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] = mtimes(a,b)
0002 %C=A*B: Matrix-by-matrix, matrix-by-vector, matrix-by-number in QTT-Tucker
0003 %   [C]=MTIMES(A,B) Matrix multiplication for the QTT_TUCKER class
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 isa(a,'double') && isa(b,'qtt_tucker')
0016     c=b;
0017     c.core=a*b.core;
0018 elseif isa(a,'qtt_tucker') && isa(b,'double') 
0019     c=a;
0020     c.core=a.core*b;
0021 elseif (isa(a,'qtt_tucker'))&&(isa(b, 'qtt_tucker'))
0022     % mtimes of tucker factors (whatever it is)
0023     d = a.dphys;
0024     c = qtt_tucker;
0025     c.dphys = d;
0026     c.tuck = cell(d,1);
0027     for i=1:d
0028         c.tuck{i} = a.tuck{i}*b.tuck{i};
0029     end;
0030     c.core = tt_tensor;
0031     c.core.d = d;
0032     rca = a.core.r;
0033     rcb = b.core.r;
0034     rta = a.core.n;
0035     rtb = b.core.n;
0036     c.core.r = rca.*rcb;
0037     c.core.n = rta.*rtb;
0038     c.core.ps = cumsum([1; c.core.r(1:d).*c.core.n.*c.core.r(2:d+1)]);
0039     c.core.core = zeros(c.core.ps(d+1)-1,1);
0040     for i=1:d
0041         cra = a.core{i};
0042         cra = reshape(cra, rca(i)*rta(i)*rca(i+1), 1);
0043         crb = b.core{i};
0044         crb = reshape(crb, 1, rcb(i)*rtb(i)*rcb(i+1));
0045         crc = cra*crb;
0046         crc = reshape(crc, rca(i), rta(i), rca(i+1), rcb(i), rtb(i), rcb(i+1));
0047         crc = permute(crc, [1, 4, 2, 5, 3, 6]);
0048         c.core.core(c.core.ps(i):c.core.ps(i+1)-1) = crc(:);
0049     end;
0050 else
0051     error('Use mtimes(full(A),full(B)).');
0052 end

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