Home > tt2 > @tt_tensor > subsasgn.m

subsasgn

PURPOSE ^

Indexing of cores of TT-format: T{I}=B

SYNOPSIS ^

function t = subsasgn(t,s,b)

DESCRIPTION ^

Indexing of cores of TT-format: T{I}=B
   T{I} = B Set i-th core to be equal to B


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t = subsasgn(t,s,b)
0002 %Indexing of cores of TT-format: T{I}=B
0003 %   T{I} = B Set i-th core to be equal to B
0004 %
0005 %
0006 % TT-Toolbox 2.2, 2009-2012
0007 %
0008 %This is TT Toolbox, written by Ivan Oseledets et al.
0009 %Institute of Numerical Mathematics, Moscow, Russia
0010 %webpage: http://spring.inm.ras.ru/osel
0011 %
0012 %For all questions, bugs and suggestions please mail
0013 %ivan.oseledets@gmail.com
0014 %---------------------------
0015  switch s(1).type
0016      case '.'
0017          switch s(1).subs
0018              case 'n'
0019                  if (size(b,1)==1)
0020                      b=b.';
0021                  end;
0022                  if (numel(s)>1)
0023                      s = s(2:end);
0024                      t.n = subsasgn(t.n, s, b);
0025                  else
0026                      t.n = b;
0027                  end;
0028 %                  if (numel(s)>1)&&(strcmp(s(2).type,'()'))
0029 %                      if (size(s(2).subs{1},1)==1)
0030 %                          s(2).subs{1}=s(2).subs{1}';
0031 %                      end;
0032 %                      t.n(s(2).subs{1})=b;
0033 %                  else
0034 %                      t.n=b;
0035 %                  end;
0036              case 'r'
0037                  if (size(b,1)==1)
0038                      b=b.';
0039                  end;
0040                  if (numel(s)>1)&&(strcmp(s(2).type,'()'))
0041                      if (size(s(2).subs{1},1)==1)
0042                          s(2).subs{1}=s(2).subs{1}';
0043                      end;
0044                      t.r(s(2).subs{1})=b;
0045                  else
0046                      t.r=b;
0047                  end;
0048              case 'core'                 
0049                  if (size(b,1)==1)
0050                      b=b.';
0051                  end;
0052                  % I don't want to dispatch all the rest subs to the core,
0053                  % because MATLAB will copy it. Fortunately, only () is
0054                  % reasonable here.
0055                  if (numel(s)>1)&&(strcmp(s(2).type,'()'))
0056                      if (size(s(2).subs{1},1)==1)
0057                          s(2).subs{1}=s(2).subs{1}';
0058                      end;
0059                      t.core(s(2).subs{1})=b;
0060                  else
0061                      t.core=b;
0062                  end;
0063              case 'd'
0064                  t.d=b;
0065              case 'ps'
0066                  if (size(b,1)==1)
0067                      b=b.';
0068                  end;
0069                  if (numel(s)>1)&&(strcmp(s(2).type,'()'))
0070                      if (size(s(2).subs{1},1)==1)
0071                          s(2).subs{1}=s(2).subs{1}';
0072                      end;
0073                      t.ps(s(2).subs{1})=b;
0074                  else
0075                      t.ps=b;
0076                  end;
0077              otherwise
0078                  error(['Cannot change field ', s.subs, ' directly.']);
0079          end
0080      case '{}'
0081          % Insert one core (r1-n-r2!!!!!! not n-r1-r2!) into the TT2
0082          r1 = size(b,1);
0083          n1 = size(b,2);
0084          r2 = size(b,3);
0085          i = s.subs{1};
0086 %          if (i==1)
0087 %              r2 = r1;
0088 %              r1 = 1;
0089 %          end;
0090          n = t.n;
0091          d = t.d;
0092          r = t.r;
0093          cr = t.core;
0094          ps = t.ps;
0095          % Update the positions of the untouched cores
0096          psnew = ps;
0097          psnew(i+1:end) = ps(i+1:end)-(ps(i+1)-ps(i))+n1*r1*r2;
0098          cr(psnew(i+1):psnew(d+1)-1) = cr(ps(i+1):ps(d+1)-1);
0099 %          if (i~=1)
0100 %              b = permute(b, [2, 1, 3]); % We have r1,n1,r2 in the new format
0101 %          end;
0102          % Update the current core
0103          cr(psnew(i):psnew(i+1)-1)=b(:);
0104          cr = cr(1:psnew(d+1)-1);
0105          % Stuff evrthg back
0106          n(i)=n1;
0107          r(i)=r1;
0108          r(i+1)=r2;
0109          t.n = n;
0110          t.r = r;
0111          t.core = cr;
0112          t.ps = psnew;
0113      otherwise
0114          error('Invalid subsasgn.');
0115  end
0116 
0117

Generated on Wed 08-Feb-2012 18:20:24 by m2html © 2005