Home > manopt > manifolds > ttfixedrank > TTeMPS_1.1 > @TTeMPS_block > innerprod.m

innerprod

PURPOSE ^

INNERPROD Inner product between two TT/MPS tensors.

SYNOPSIS ^

function res = innerprod( x, y, dir, upto )

DESCRIPTION ^

INNERPROD Inner product between two TT/MPS tensors.
   innerprod(X,Y) computes the inner product between the TT/MPS tensors X and Y.
   Assumes that the first rank of both tensors, X.rank(1) and Y.rank(1), is 1. 
   The last rank may be different from 1, resulting in a matrix of size 
   [X.rank(end), Y.rank(end)].

   See also NORM

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function res = innerprod( x, y, dir, upto )
0002     %INNERPROD Inner product between two TT/MPS tensors.
0003     %   innerprod(X,Y) computes the inner product between the TT/MPS tensors X and Y.
0004     %   Assumes that the first rank of both tensors, X.rank(1) and Y.rank(1), is 1.
0005     %   The last rank may be different from 1, resulting in a matrix of size
0006     %   [X.rank(end), Y.rank(end)].
0007     %
0008     %   See also NORM
0009 
0010     %   TTeMPS Toolbox.
0011     %   Michael Steinlechner, 2013-2016
0012     %   Questions and contact: michael.steinlechner@epfl.ch
0013     %   BSD 2-clause license, see LICENSE.txt
0014 
0015     if ~exist( 'dir', 'var' )
0016         dir = 'LR';
0017     end
0018     if ~exist( 'upto', 'var' )
0019         if strcmpi( dir, 'LR')
0020             upto = x.order;
0021         else
0022             upto = 1;
0023         end
0024     end
0025 
0026     % Left-to-Right procedure
0027     if strcmpi( dir, 'LR')
0028         
0029         res = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');
0030 
0031         for i = 2:upto
0032             tmp = tensorprod_ttemps( x.U{i}, res', 1);
0033             res = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
0034         end
0035 
0036     % Right-to-Left procedure
0037     elseif strcmpi( dir, 'RL')
0038         d = x.order;
0039         res = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';
0040         
0041         for i = d-1:-1:upto
0042             tmp = tensorprod_ttemps( x.U{i}, res', 3);
0043             res = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
0044         end
0045 
0046     else
0047         error('Unknown direction specified. Choose either LR (default) or RL')
0048     end
0049 
0050 end
0051

Generated on Fri 30-Sep-2022 13:18:25 by m2html © 2005