0001 function [c] = mtimes(a,b)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
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
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