Home > manopt > manifolds > ttfixedrank > TTeMPS_1.1 > @TTeMPS_op > TTeMPS_op.m

TTeMPS_op

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef TTeMPS_op
0002 % TTeMPS_op
0003 %
0004 %   A MATLAB class for representing and manipulating tensor operators
0005 %   in the TT/MPS operator format.
0006 %
0007 
0008 %   TTeMPS Toolbox.
0009 %   Michael Steinlechner, 2013-2016
0010 %   Questions and contact: michael.steinlechner@epfl.ch
0011 %   BSD 2-clause license, see LICENSE.txt
0012 
0013 
0014 properties( SetAccess = private, GetAccess = public )
0015 
0016     U           % core tensors as 4D doubles
0017     rank
0018     order
0019     size_row
0020     size_col
0021 
0022 end
0023 
0024 % Set methods for Cores
0025 methods
0026     
0027     function A = set.U( A, U_);
0028         
0029         A.U = U_;
0030         A = update_properties( A );
0031 
0032     end
0033 
0034 
0035     function A = update_properties( A );
0036 
0037         rank_ = cellfun( @(x) size(x,1), A.U);
0038         A.rank = [rank_, size(A.U{end},4)];
0039         A.size_col = cellfun( @(y) size(y,2), A.U);
0040         A.size_row = cellfun( @(y) size(y,3), A.U);
0041         A.order = length( A.size_row );
0042 
0043     end
0044 
0045 end
0046 
0047 
0048 
0049 methods( Access = public )
0050 
0051     function A = TTeMPS_op(varargin)
0052     %TTEMPS Construct a tensor in TT/MPS format and return TTeMPS object.
0053     %
0054     %   A = TTEMPS() creates a zero TT/MPS tensor
0055     %
0056     %   A = TTEMPS(CORES) creates a TT/MPS tensor with core tensors C taken
0057     %   from the cell array CORES
0058     %
0059     %   A = TTEMPS(CORES, ORTH) creates a TT/MPS tensor with core tensors C
0060     %   taken from the cell array CORES. ORTH specifies the position of
0061     %   orthogonalization (default = 0, no orthogonalization).
0062     %
0063 
0064         % Default constructor
0065         if (nargin == 0)
0066           
0067             A = TTeMPS_op( {0 0 0} );
0068             return;
0069           
0070         elseif (nargin == 1)
0071 
0072             % CAREFUL, add sanity check here
0073             A.U = varargin{1};
0074 
0075             A = update_properties( A );
0076 
0077         else
0078             error('Invalid number of arguments.')
0079         end
0080     end
0081 
0082     % Other public functions
0083     disp( A, name );
0084     display( A );
0085 
0086     res = contract( A, x, y, idx );
0087     B = TTeMPS_op_to_TT_matrix( A );
0088     B = TTeMPS_op_to_TTeMPS( A );
0089     y = apply( A, x, idx );
0090     A = round(A, tol );
0091     
0092     A = plus( A, B );
0093     A = mtimes( B, A );
0094 
0095     Afull = full( A );
0096     
0097 end
0098 
0099 end

Generated on Sun 05-Sep-2021 17:57:00 by m2html © 2005