Home > manopt > manifolds > ttfixedrank > TTeMPS_1.1 > @TTeMPS_op_laplace > contract.m

# contract

## PURPOSE

CONTRACT Contraction of two TT/MPS tensors with inner TT/MPS Laplace operator.

## SYNOPSIS

function res = contract( A, X, mu )

## DESCRIPTION

```CONTRACT Contraction of two TT/MPS tensors with inner TT/MPS Laplace operator.
Z = CONTRACT(A,X,IDX) contracts all cores of the two TT/MPS tensors X and Y=apply(A,X) except
core IDX. Result Z is a matrix of size
[ X.rank(IDX)*A.size_col(IDX)*X.rank(IDX+1), X.rank(IDX)*A.size_row(IDX),X.rank(IDX+1) ].

## CROSS-REFERENCE INFORMATION

This function calls:
• full FULL Convert TTeMPS tensor to full array
• innerprod INNERPROD Inner product between two TT/MPS tensors.
• full FULL Convert TTeMPS tensor to full array
• innerprod INNERPROD Inner product between two TT/MPS tensors.
• full FULL Convert TTeMPS_op operator to full array
• matricize MATRICIZE Matricize 3D Matlab array.
This function is called by:

## SOURCE CODE

```0001 function res = contract( A, X, mu )
0002     %CONTRACT Contraction of two TT/MPS tensors with inner TT/MPS Laplace operator.
0003     %   Z = CONTRACT(A,X,IDX) contracts all cores of the two TT/MPS tensors X and Y=apply(A,X) except
0004     %   core IDX. Result Z is a matrix of size
0005     %       [ X.rank(IDX)*A.size_col(IDX)*X.rank(IDX+1), X.rank(IDX)*A.size_row(IDX),X.rank(IDX+1) ].
0006     %
0008
0009     %   TTeMPS Toolbox.
0010     %   Michael Steinlechner, 2013-2016
0011     %   Questions and contact: michael.steinlechner@epfl.ch
0013
0014     V = cell(1, A.order);
0015
0016     Y = A.apply(X);
0017     if mu > 1
0018         left = innerprod( X, Y, 'LR', mu-1 );
0019         left = reshape( left, [X.rank(mu), A.rank(mu), X.rank(mu)] );
0020         left = reshape( permute(left, [1 3 2]), [X.rank(mu)*X.rank(mu), A.rank(mu)] );
0021         tmp = reshape( full(A.U{mu}), [A.rank(mu), A.rank(mu+1), A.size_col(mu), A.size_row(mu)] );
0022         tmp = ipermute( tmp, [1 4 2 3] );
0023         res = left * reshape(tmp, [A.rank(mu), A.size_col(mu)*A.size_row(mu)*A.rank(mu+1)] );
0024         %res = left * reshape(A.U{mu}, [A.rank(mu), A.size_col(mu)*A.size_row(mu)*A.rank(mu+1)] );
0025     else
0026         tmp = reshape( full(A.U{1}), [A.rank(1), A.rank(2), A.size_col(1), A.size_row(1)] );
0027         tmp = ipermute( tmp, [1 4 2 3] );
0028         res = tmp;
0029         %res = A.U{1};
0030     end
0031     if mu < X.order
0032         right = innerprod( X, Y, 'RL', mu+1 );
0033         right = reshape( right, [X.rank(mu+1), A.rank(mu+1), X.rank(mu+1)] );
0034         right = matricize( right, 2);
0035         res = reshape( res, [ X.rank(mu)*X.rank(mu)*A.size_col(mu)*A.size_row(mu), A.rank(mu+1) ]);
0036         res = res * right;
0037     end
0038
0039     res = reshape( res, [X.rank(mu), X.rank(mu), A.size_col(mu), A.size_row(mu), X.rank(mu+1), X.rank(mu+1) ] );
0040     res = permute( res, [1 3 5 2 4 6] );
0041     res = reshape( res, [X.rank(mu)*A.size_col(mu)*X.rank(mu+1), X.rank(mu)*A.size_row(mu)*X.rank(mu+1) ] );
0042
0043 end```

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