Home > tt2 > @tt_tensor > times.m

times

PURPOSE ^

A=B.*C

SYNOPSIS ^

function [a]=times(b,c,varargin)

DESCRIPTION ^

A=B.*C
   [A]=TIMES(B,C) Hadamard product of two TT-tensors


 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]=times(b,c,varargin)
0002 %A=B.*C
0003 %   [A]=TIMES(B,C) Hadamard product of two TT-tensors
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 
0016 if (nargin == 2 )
0017     d=b.d; n=b.n; crb=b.core; crc=c.core; rb=b.r; rc=c.r;
0018     psb=b.ps; psc=c.ps;
0019     %Ranks are just a product
0020     a=tt_tensor;
0021     ra=rb.*rc;
0022     psa=cumsum([1;n(1:d).*ra(1:d).*ra(2:d+1)]);
0023     sz=dot(n(1:d).*ra(1:d),ra(2:d+1));
0024     cra=zeros(sz,1);
0025     for i=1:d
0026        cr1=crb(psb(i):psb(i+1)-1);
0027        cr2=crc(psc(i):psc(i+1)-1);
0028        cr1=reshape(cr1,[rb(i),n(i),rb(i+1)]);       
0029        cr2=reshape(cr2,[rc(i),n(i),rc(i+1)]);
0030        % rewrite in in the vectorized form
0031        cr1 = permute(cr1, [2, 1, 3]);
0032        cr1 = reshape(cr1, n(i)*rb(i)*rb(i+1), 1);
0033        ons = ones(1, rc(i)*rc(i+1));
0034        cr1 = cr1*ons;
0035        cr1 = reshape(cr1, n(i), rb(i), rb(i+1), rc(i), rc(i+1));
0036        cr1 = permute(cr1, [1, 2, 4, 3, 5]);
0037        cr1 = reshape(cr1, n(i), rb(i)*rc(i)*rb(i+1)*rc(i+1));
0038        cr2 = permute(cr2, [2, 1, 3]);
0039        cr2 = reshape(cr2, n(i)*rc(i)*rc(i+1), 1);
0040        ons = ones(1, rb(i)*rb(i+1));
0041        cr2 = cr2*ons;
0042        cr2 = reshape(cr2, n(i), rc(i), rc(i+1), rb(i), rb(i+1));
0043        cr2 = permute(cr2, [1, 4, 2, 5, 3]);
0044        cr2 = reshape(cr2, n(i), rb(i)*rc(i)*rb(i+1)*rc(i+1));       
0045        cr = cr1.*cr2;
0046        cr = reshape(cr, n(i), rb(i)*rc(i), rb(i+1)*rc(i+1));
0047        cr = permute(cr, [2, 1, 3]);
0048 %        cr=zeros(ra(i),n(i),ra(i+1));
0049 %        for j=1:n(i)
0050 %           cr(:,j,:)=kron(reshape(cr1(:,j,:),rb(i),rb(i+1)),reshape(cr2(:,j,:),rc(i),rc(i+1)));
0051 %        end
0052        cra(psa(i):psa(i+1)-1)=cr(:);
0053     end
0054     a.d=d;
0055     a.n=n;
0056     a.r=ra;
0057     a.ps=psa;
0058     a.core=cra;
0059 elseif (nargin == 3)
0060      error('Krylov method is not yet supported, come again later');
0061 end
0062 return
0063 end

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