Home > tt2 > core > tt_rand.m

tt_rand

PURPOSE ^

Generates a random tensor

SYNOPSIS ^

function [tt]=tt_rand(n,d,r)

DESCRIPTION ^

Generates a random tensor
   [TT]=TT_RAND(N,D,R) Generates a random tensor with dimensions specified
   by (N,D), where N can be a number of an array of dimension D, R is a
   rank or a array of dimension d+1


 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 [tt]=tt_rand(n,d,r)
0002 %Generates a random tensor
0003 %   [TT]=TT_RAND(N,D,R) Generates a random tensor with dimensions specified
0004 %   by (N,D), where N can be a number of an array of dimension D, R is a
0005 %   rank or a array of dimension d+1
0006 %
0007 %
0008 % TT-Toolbox 2.2, 2009-2012
0009 %
0010 %This is TT Toolbox, written by Ivan Oseledets et al.
0011 %Institute of Numerical Mathematics, Moscow, Russia
0012 %webpage: http://spring.inm.ras.ru/osel
0013 %
0014 %For all questions, bugs and suggestions please mail
0015 %ivan.oseledets@gmail.com
0016 %---------------------------
0017 if ( numel(n) == 1 ) 
0018  n = n * ones(d,1);
0019 end
0020 if ( numel(r) == 1 )
0021  r = r * ones(d+1,1); 
0022  r(1) = 1;
0023  r(d+1)=1;
0024 end
0025 r=r(:);
0026 n=n(:);
0027 tt=tt_tensor;
0028 tt.n=n;
0029 tt.r=r;
0030 tt.d=d;
0031 ps=cumsum([1;n.*r(1:d).*r(2:d+1)]);
0032 tt.ps=ps;
0033 cr=randn(ps(d+1)-1,1);
0034 tt.core=cr;
0035 return
0036 end

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