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

subsref

PURPOSE ^

SUBSREF Subscripted reference for TTeMPS.

SYNOPSIS ^

function out = subsref(x, s)

DESCRIPTION ^

SUBSREF Subscripted reference for TTeMPS.

   Examples:
   x([2,3,1]) computes and returns the element (2,3,1) of x.
   x( ind ) computes and returns all elements x(ind(i,:)) for i = 1:size(ind,1).
   x(:) returns the vectorization of full(x) (careful!)
   x{i} returns the i-th core of x, shorthand for x.U{i}

   See also TTEMPS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function out = subsref(x, s)
0002     %SUBSREF Subscripted reference for TTeMPS.
0003     %
0004     %   Examples:
0005     %   x([2,3,1]) computes and returns the element (2,3,1) of x.
0006     %   x( ind ) computes and returns all elements x(ind(i,:)) for i = 1:size(ind,1).
0007     %   x(:) returns the vectorization of full(x) (careful!)
0008     %   x{i} returns the i-th core of x, shorthand for x.U{i}
0009     %
0010     %   See also TTEMPS.
0011 
0012     %   TTeMPS Toolbox.
0013     %   Michael Steinlechner, 2013-2016
0014     %   Questions and contact: michael.steinlechner@epfl.ch
0015     %   BSD 2-clause license, see LICENSE.txt
0016     
0017 
0018     switch s(1).type
0019 
0020     case '.'
0021 
0022         prop = properties('TTeMPS');
0023         if( any(strcmp(s(1).subs, prop) ) ),
0024             out = builtin('subsref', x, s);
0025         else
0026             ll = length(prop);
0027             proplist = repmat({', '}, 2*ll-1, 1);
0028             proplist(1:2:end) = prop;
0029             proplist = cat(2,proplist{:});
0030             error(['Object TTeMPS does not have field ' s(1).subs ...
0031             '. The following fields are available: ' proplist '.']);
0032         end
0033 
0034     case '()'
0035         % x(:)
0036         ind = s(1).subs{1};
0037         if(length(ind) == 1) && (ind == ':')
0038             out = full(x);
0039             out = out(:);
0040             % e.g. x( [1,2,3; 4 5 6; 7 8 9; 3 5 3]) for d = 3 tensor
0041         elseif(size(ind,2) == x.order)
0042             
0043             r = x.rank;
0044             %out = zeros(size(ind,1), 1);
0045             
0046             %C = cell(1,x.order);
0047             %for i=1:x.order
0048             %    C{i} = permute( x.U{i}, [1 3 2]);
0049             %end
0050             %for i = 1:size(ind,1)
0051             %    p = C{1}(:,:,ind(i,1));
0052             %    for j = 2:size(ind,2)
0053             %        p = p * C{j}(:,:,ind(i,j));
0054             %    end
0055             %    out(i) = p;
0056             %end
0057             n = x.size;
0058             
0059             C = cell(1,x.order);
0060             for i=1:x.order
0061                 C{i} = permute( x.U{i}, [1 3 2]);
0062                 C{i} = unfold( C{i}, 'right');
0063             end
0064             
0065             out = TTeMPS.subsref_mex( n, r, transpose(ind), C);
0066 
0067             %for i = 1:size(ind,1)
0068             %    p = C{1}(:, (ind(i,1)-1)*r(2)+1:ind(i,1)*r(2));
0069             %    for j = 2:size(ind,2)
0070             %        p = p * C{j}(: , (ind(i,j)-1)*r(j+1)+1:ind(i,j)*r(j+1));
0071             %    end
0072             %    out(i) = p;
0073             %end
0074                     
0075     
0076         else
0077             error('Number of indices does not match order of TTeMPS tensor.');
0078         end
0079 
0080 
0081     case '{}'
0082 
0083         if(length(s(1).subs) ~= 1 || ~isnumeric(s(1).subs{1}) || ...
0084             s(1).subs{1} <= 0)
0085             error('{} only takes one positive integer.');
0086         end
0087 
0088         ii = s(1).subs{1};
0089         if(ii > x.order)
0090             error('Index exceeds number of dimensions');
0091         end
0092         out = builtin('subsref', x.U, s);
0093 
0094     end

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