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

TTeMPS_block

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_block
0002 % TTeMPS_block
0003 %
0004 %   A MATLAB class for representing and manipulating tensors
0005 %   in the TT/MPS Block-mu 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 properties( SetAccess = public, GetAccess = public )
0014 
0015     U           % core tensors
0016     mu          % position of superblock
0017     p           % size of block
0018 end
0019 
0020 % Dependent properties
0021 properties( Dependent = true, SetAccess = private, GetAccess = public )
0022 
0023     rank
0024     order
0025     size
0026 
0027 end
0028 
0029 % Get methods for dependent properties (computed on-the-fly)
0030 methods
0031 
0032     function rank_ = get.rank(x)
0033         rank_ = cellfun( @(x) size(x,1), x.U);
0034         rank_ = [rank_, size(x.U{end},3)];
0035     end
0036    
0037     function size_ = get.size(x)
0038         size_ = cellfun( @(y) size(y,2), x.U);
0039     end
0040 
0041     function order_ = get.order(x)
0042         order_ = length( x.size );
0043     end
0044 end
0045 
0046 
0047 methods( Access = public )
0048 
0049     function x = TTeMPS_block(varargin)
0050     %TTEMPS_BLOCK Construct a tensor in TT/MPS block-mu format and return TTeMPS_block object.
0051     %
0052     %   X = TTEMPS_BLOCK() creates a zero TT/MPS tensor
0053     %
0054     %   X = TTEMPS_BLOCK(CORES) creates a TT/MPS tensor with core tensors C taken
0055     %   from the cell array CORES
0056     %
0057     %   X = TTEMPS_BLOCK(CORES, ORTH) creates a TT/MPS tensor with core tensors C
0058     %   taken from the cell array CORES. ORTH specifies the position of
0059     %   orthogonalization (default = 0, no orthogonalization).
0060     %
0061 
0062         % Default constructor
0063         if (nargin == 0)
0064           
0065             x = TTeMPS_block( {0 0 0}, 1 );
0066             return;
0067           
0068         elseif (nargin == 2)
0069 
0070             % CAREFUL, add sanity check here
0071             U = varargin{1};
0072             mu = varargin{2}; 
0073             x = TTeMPS_block( U, mu, size(U{mu},4) );
0074             return;
0075 
0076         elseif (nargin == 3)
0077 
0078             x.U = varargin{1};
0079             x.mu = varargin{2};
0080             x.p = varargin{3};
0081 
0082         else
0083             error('Invalid number of arguments.')
0084         end
0085     end
0086 
0087     function res = TTeMPS_block_to_TTeMPS( x )
0088         mu = x.mu;
0089         tmp = permute( x.U{mu}, [1 2 4 3] );
0090         tmp = reshape( tmp, [x.rank(mu), x.size(mu)*x.p, x.rank(mu+1)]);
0091 
0092         res = TTeMPS({x.U{1:mu-1}, tmp, x.U{mu+1:end}});
0093     end
0094 
0095     function res = getVector( x, idx, condense )
0096         if ~exist( 'condense', 'var' )
0097             condense = false;
0098         end
0099         tmp = x.U{x.mu}(:,:,:,idx);
0100         res = TTeMPS({x.U{1:x.mu-1}, tmp, x.U{x.mu+1:end}});
0101         if condense
0102             res = round(res, 1e-16);
0103         end
0104     end
0105 
0106 
0107     % Other public functions
0108     y = full( x );
0109     [x, r] = orth_at( x, pos, dir, apply );
0110     res = innerprod( x, y, dir, upto, storeParts );
0111     res = shift( x, nu, tol, maxrank);
0112     res = norm( x );
0113     res = contract( x, y, idx );
0114     x = round( x, tol );
0115     x = truncate( x, r );
0116     x = uminus( x );
0117     x = uplus( x );
0118     z = plus( x, y );
0119     z = minus( x, y );
0120     x = mtimes( a, x );
0121     z = hadamard( x, y, idx );
0122     [xl,xr,g] = gauge_matrices( x );
0123     disp( x, name );
0124     display( x );
0125     
0126 end
0127 
0128 methods( Static, Access = public )
0129 
0130     function res = TTeMPS_to_TTeMPS_block( x, mu, p )
0131 
0132         U = x.U;
0133         tmp = reshape( U{mu}, [x.rank(mu), x.size(mu)/p, p, x.rank(mu+1)]);
0134         tmp = permute( tmp, [1 2 4 3] );
0135         res = TTeMPS_block({U{1:mu-1}, tmp, U{mu+1:x.order}}, mu, p);
0136     end
0137 
0138 end
0139 
0140 end

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