TTEMPS_RAND Create random TTeMPS tensor X = TTEMPS_RAND(R, N) creates a length(N)-dimensional TTeMPS tensor of size N(1)*N(2)*...N(end) with ranks R by filling the cores with iid uniform random numbers in [0, 1]. Note that the first and last entry of the rank vector must be 1.
0001 function x = TTeMPS_rand(r, n) 0002 % TTEMPS_RAND Create random TTeMPS tensor 0003 % X = TTEMPS_RAND(R, N) creates a length(N)-dimensional TTeMPS tensor 0004 % of size N(1)*N(2)*...N(end) with ranks R by filling the cores with 0005 % iid uniform random numbers in [0, 1]. 0006 % Note that the first and last entry of the rank vector must be 1. 0007 % 0008 0009 % TTeMPS Toolbox. 0010 % Michael Steinlechner, 2013-2016 0011 % Questions and contact: michael.steinlechner@epfl.ch 0012 % BSD 2-clause license, see LICENSE.txt 0013 0014 if length(r) ~= length(n)+1 0015 error('Size mismatch in arguments') 0016 end 0017 0018 U = cell(1, length(n)); 0019 for i = 1:length(n) 0020 U{i} = rand(r(i), n(i), r(i+1)); 0021 end 0022 x = TTeMPS(U); 0023 end