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

# innerprod

## PURPOSE

INNERPROD Inner product between two TT/MPS tensors.

## SYNOPSIS

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

## 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)].

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

## SOURCE CODE

```0001 function res = innerprod( x, y, dir, upto, storeParts )
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     %
0009
0010     %   TTeMPS Toolbox.
0011     %   Michael Steinlechner, 2013-2016
0012     %   Questions and contact: michael.steinlechner@epfl.ch
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     if ~exist( 'storeParts', 'var' )
0026         storeParts = false;
0027     end
0028     if storeParts
0029         res = cell(1, x.order);
0030     end
0031
0032     % Left-to-Right procedure
0033     if strcmpi( dir, 'LR')
0034
0035         if storeParts
0036             res{1} = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');
0037         else
0038             res = unfold( x.U{1}, 'left')' * unfold( y.U{1}, 'left');
0039         end
0040
0041         for i = 2:upto
0042             if storeParts
0043                 tmp = tensorprod_ttemps( x.U{i}, res{i-1}', 1);
0044                 res{i} = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
0045             else
0046                 tmp = tensorprod_ttemps( x.U{i}, res', 1);
0047                 res = unfold( tmp, 'left')' * unfold( y.U{i}, 'left');
0048             end
0049         end
0050
0051     % Right-to-Left procedure
0052     elseif strcmpi( dir, 'RL')
0053         d = x.order;
0054         if storeParts
0055             res{d} = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';
0056         else
0057             res = conj(unfold( x.U{d}, 'right')) * unfold( y.U{d}, 'right').';
0058         end
0059
0060         for i = d-1:-1:upto
0061             if storeParts
0062                 tmp = tensorprod_ttemps( x.U{i}, res{i+1}', 3);
0063                 res{i} = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
0064             else
0065                 tmp = tensorprod_ttemps( x.U{i}, res', 3);
0066                 res = conj(unfold( tmp, 'right')) * unfold( y.U{i}, 'right').';
0067             end
0068         end
0069
0070     else
0071         error('Unknown direction specified. Choose either LR (default) or RL')
0072     end
0073
0074 end
0075```

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