Mentions légales du service

Skip to content
Snippets Groups Projects
Commit cf717ca3 authored by hhakim's avatar hhakim
Browse files

Add seed argument to matfaust.rand.

Useful for reproducible examples.
parent 587f90af
Branches
Tags
No related merge requests found
......@@ -54,6 +54,7 @@
%> The default value is 'real'.
%> @param 'dev', str 'gpu or 'cpu' to create the random Faust on CPU or GPU (by default on CPU).
%> @param 'class', str 'double' (by default) or 'single' to select the scalar type used for the Faust generated.
%> @param 'seed', int seed to initialize the PRNG used to generate the Faust factors. If 0 (default) the seed will be initialized with a random value depending of the time clock.
%>
%>
%> @retval F the random Faust.
......@@ -130,6 +131,7 @@ function F = rand(M, N, varargin)
argc = length(varargin);
dev = 'cpu';
class = 'double';
seed = 0;
if(argc > 0)
for i=1:2:argc
if(argc > i)
......@@ -185,6 +187,12 @@ function F = rand(M, N, varargin)
else
per_row = tmparg;
end
case 'seed'
if(argc == i || ~ isscalar(tmparg) || ~ isreal(tmparg))
error('isscalar keyword argument is not followed by a real scalar')
else
seed = uint64(tmparg);
end
case 'dev'
if(argc == i || ~ strcmp(tmparg, 'cpu') && ~ startsWith(tmparg, 'gpu'))
error('dev keyword argument is not followed by a valid value: cpu, gpu*.')
......@@ -197,6 +205,7 @@ function F = rand(M, N, varargin)
else
class = tmparg;
end
case 'seed'
otherwise
if((isstr(varargin{i}) || ischar(varargin{i})) && ~ strcmp(tmparg, 'cpu') && ~ startsWith(tmparg, 'gpu') && ~ strcmp(tmparg, 'dense') && ~ strcmp(tmparg, 'sparse') && ~ strcmp(tmparg, 'mixed') && ~ strcmp(tmparg, 'real') && ~ strcmp(tmparg, 'complex'))
error([ tmparg ' unrecognized argument'])
......@@ -227,25 +236,25 @@ function F = rand(M, N, varargin)
end
if(strcmp(dev, 'cpu'))
if(field == COMPLEX)
core_obj = mexFaustCplx('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
core_obj = mexFaustCplx('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row, seed);
is_real = false;
else %if(field == REAL)
if(strcmp(class, 'double'))
core_obj = mexFaustReal('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
core_obj = mexFaustReal('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row, seed);
else % single
core_obj = mexFaustRealFloat('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
core_obj = mexFaustRealFloat('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row, seed);
end
is_real = true;
end
else
if(field == COMPLEX)
core_obj = mexFaustGPUCplx('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
core_obj = mexFaustGPUCplx('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row, seed);
is_real = false;
else %if(field == REAL)
if(strcmp(class, 'double'))
core_obj = mexFaustGPUReal('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
core_obj = mexFaustGPUReal('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row, seed);
else % float
core_obj = mexFaustGPURealFloat('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row);
core_obj = mexFaustGPURealFloat('rand', num_rows, num_cols, fac_type, min_num_factors, max_num_factors, min_dim_size, max_dim_size, density, per_row, seed);
end
is_real = true;
end
......
......@@ -6,8 +6,8 @@ void faust_rand(const mxArray **prhs, const int nrhs, mxArray **plhs, const int
if(nlhs!=1)
mexErrMsgTxt("rand(): 1 variable result is expected.");
if(nrhs < 6)
mexErrMsgTxt("rand(): wrong number of arguments (must be 6 to 7)");
if(nrhs < 10)
mexErrMsgTxt("rand(): wrong number of arguments (must be at least 10)");
int num_rows = mxGetScalar(prhs[1]), num_cols =mxGetScalar(prhs[2]);
faust_unsigned_int t = (faust_unsigned_int) mxGetScalar(prhs[3]),
......@@ -17,6 +17,10 @@ void faust_rand(const mxArray **prhs, const int nrhs, mxArray **plhs, const int
max_dim_size = (faust_unsigned_int) mxGetScalar(prhs[7]);
float density = (float) mxGetScalar(prhs[8]);
bool per_row = (bool) mxGetScalar(prhs[9]);
unsigned int seed = 0;
if(nrhs >= 11)
seed = (unsigned int) mxGetScalar(prhs[10]);
Faust::TransformHelper<SCALAR,DEV>* F = Faust::TransformHelper<SCALAR,DEV>::randFaust(
num_rows,
......@@ -27,7 +31,8 @@ void faust_rand(const mxArray **prhs, const int nrhs, mxArray **plhs, const int
min_dim_size,
max_dim_size,
density,
per_row);
per_row,
seed);
if(F) //not NULL
plhs[0]=convertPtr2Mat<Faust::TransformHelper<SCALAR,DEV> >(F);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment