0001 function out = subsref(x, s)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
0036 ind = s(1).subs{1};
0037 if(length(ind) == 1) && (ind == ':')
0038 out = full(x);
0039 out = out(:);
0040
0041 elseif(size(ind,2) == x.order)
0042
0043 r = x.rank;
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
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
0068
0069
0070
0071
0072
0073
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