Home > tt2 > @tt_tensor > mtimes.m

mtimes

PURPOSE ^

C = A*B

SYNOPSIS ^

function [c] = mtimes(a,b)

DESCRIPTION ^

   C = A*B
   [C]=MTIMES(A,B)
   TT-Tensor-by-Matrix multiplication

   Either A or B may be a TT-tensor. The rest argument must be a matrix
   with sizes consistent to the respective "tail" rank of a tensor (or a
   scalar).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [c] = mtimes(a,b)
0002 %   C = A*B
0003 %   [C]=MTIMES(A,B)
0004 %   TT-Tensor-by-Matrix multiplication
0005 %
0006 %   Either A or B may be a TT-tensor. The rest argument must be a matrix
0007 %   with sizes consistent to the respective "tail" rank of a tensor (or a
0008 %   scalar).
0009 
0010 if isa(a,'double') && isa(b,'tt_tensor')
0011     d = b.d;
0012     cr1 = b.core(b.ps(1):b.ps(2)-1);
0013     cr1 = reshape(cr1, b.r(1), b.n(1)*b.r(2));
0014     if (numel(a)==1) 
0015         rnew = b.r(1);
0016     else
0017         rnew = size(a,1);
0018     end;
0019     dps = rnew*b.n(1)*b.r(2) - b.r(1)*b.n(1)*b.r(2);
0020     cr1 = a*cr1;
0021     
0022     c = b;
0023     c.core=c.core(b.ps(2):b.ps(d+1)-1);
0024     c.core = [cr1(:); c.core(:)];
0025     c.ps(2:d+1)=b.ps(2:d+1)+dps;
0026     c.r(1) = rnew;
0027     
0028 %     c=b;
0029 %     crc=c.core;
0030 %     if (size(crc,2) == 1 )
0031 %       crc=crc.';
0032 %     end
0033 %     ps=c.ps;
0034 %     r=c.r;
0035 %     n=c.n;
0036 %     mm=crc(ps(1):ps(2)-1);
0037 %     mm=reshape(mm,[r(1),n(1)*r(2)]);
0038 %     mm=a*mm;
0039 %     crc(ps(1):ps(2)-1)=[];
0040 %     crc=[mm(:)',crc];
0041 %     r(1)=size(a,1);
0042 %     ps=ps-ps(2)+1+r(1)*n(2)*r(2);
0043 %     ps(1)=1;
0044 %     c.ps=ps;
0045 %     c.core=crc;
0046 %     c.r=r;
0047 elseif isa(a,'tt_tensor') && isa(b,'double') 
0048     d = a.d;
0049     crd = a.core(a.ps(d):a.ps(d+1)-1);
0050     crd = reshape(crd, a.r(d)*a.n(d), a.r(d+1));
0051     if (numel(b)==1) 
0052         rnew = a.r(d+1);
0053     else
0054         rnew = size(b,2);
0055     end;    
0056     ps_new = a.ps(d) + a.r(d)*a.n(d)*rnew;
0057     crd = crd*b;
0058     
0059     c = a;
0060     c.core(a.ps(d):ps_new-1)=crd(:);
0061     c.core = c.core(1:ps_new-1);
0062     c.ps(d+1)=ps_new;
0063     c.r(d+1) = rnew;
0064     
0065 else
0066     error('Use mtimes(full(A),full(B)).');
0067 end

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