Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bff69e68 authored by Nicolas Bellot's avatar Nicolas Bellot Committed by hhakim
Browse files

[wrapper matlab] generate_Faust_config with various density

parent fe2d51a5
No related branches found
No related tags found
No related merge requests found
......@@ -82,20 +82,20 @@ if(BUILD_WRAPPER_MATLAB)
# 1st factor sparse size 10x3,
# 2nd factor dense size 3x2,
# 3rd factor sparse size 2x5
add_test(NAME MATLAB_FAUST_CONFIG_REAL1 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([10,3,2,5],{'real.sparse','real.dense','real.sparse'});test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST_CONFIG_REAL1 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([10,3,2,5],{'real.sparse','real.dense','real.sparse'},0.5);test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
#test Faust with 3 real factors :
# 1st factor sparse size 5x2,
# 2nd factor dense size 2x3,
# 3rd factor sparse size 3x10
add_test(NAME MATLAB_FAUST_CONFIG_REAL2 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([5,2,3,10],{'real.dense','real.sparse','real.dense'});test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST_CONFIG_REAL2 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([5,2,3,10],{'real.dense','real.sparse','real.dense'},0.5);test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
#test Faust with 1 real factor :
# 1st factor dense size 10x3,
add_test(NAME MATLAB_FAUST_CONFIG_REAL3 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([100,10],{'real.dense'});test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST_CONFIG_REAL3 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([100,10],{'real.dense'},1.0);test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
#test Faust with 1 real factor :
# 1st factor sparse size 10x3,
add_test(NAME MATLAB_FAUST_CONFIG_REAL4 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([100,10],{'real.sparse'});test_matlab_faust(factors,prod,1000,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST_CONFIG_REAL4 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([100,10],{'real.sparse'},0.1);test_matlab_faust(factors,prod,1000,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
......@@ -103,13 +103,13 @@ if(BUILD_WRAPPER_MATLAB)
# 1st factor real dense size 10x3,
# 2nd factor complex dense size 3x2,
# 3rd factor complex dense size 2x5
add_test(NAME MATLAB_FAUST_CONFIG_CPLX1 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([10,3,2,5],{'real.dense','complex.dense','complex.dense'});test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST_CONFIG_CPLX1 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([10,3,2,5],{'real.dense','complex.dense','complex.dense'},0.5);test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
#test Faust with 3 factors :
# 1st factor real sparse size 10x3,
# 2nd factor complex dense size 3x2,
# 3rd factor complex sparse size 2x5
add_test(NAME MATLAB_FAUST_CONFIG_CPLX2 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([10,3,2,5],{'real.sparse','complex.dense','complex.sparse'});test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST_CONFIG_CPLX2 COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;[factors,prod]=generate_Faust_config([10,3,2,5],{'real.sparse','complex.dense','complex.sparse'},0.5);test_matlab_faust(factors,prod,30,0);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
## test the matlab Faust class methods with incorrect parameter
......
......@@ -65,7 +65,7 @@
% Topics in Signal Processing, 2016.
% <https://hal.archives-ouvertes.fr/hal-01167948v1>
%%
function [factors, dense]=generate_Faust_config(list_dim,type_factor)
function [factors, dense]=generate_Faust_config(list_dim,type_factor,density)
int_max = 100;
nb_fact=length(type_factor);
if (length(list_dim)-1) ~= nb_fact
......@@ -78,27 +78,55 @@ int_max = 100;
factors=cell(1,nb_fact);
dense=eye(list_dim(1));
nbr_coeff_faust = 0;
for i=1:nb_fact
nbr_coeff_faust = nbr_coeff_faust + prod(list_dim(i:i+1));
end
nbr_coeff_dense_matrix = list_dim(1)*list_dim(end);
density_per_fact = density * nbr_coeff_dense_matrix/nbr_coeff_faust;
for i=1:nb_fact
nb_row = list_dim(i);
nb_col = list_dim(i+1);
nnz_fact = round(density_per_fact*nb_row*nb_col);
if (nnz_fact == 0)
error('factor with 0 non zeros coefficent ');
else
if(nnz_fact > nb_row*nb_col)
error('too much element per factor');
end
end
type_current_fact = type_factor{i};
celltype_current_fact = strsplit(type_current_fact,'.');
scalarType = celltype_current_fact{1};
sparsityType = celltype_current_fact{2};
fact_values = double(randi(int_max,[1,nnz_fact]));
switch scalarType
case 'real'
current_fact = double(randi(int_max,nb_row,nb_col));
case 'complex'
current_fact = double(randi(int_max,nb_row,nb_col)+1i*randi(int_max,nb_row,nb_col));
fact_values = fact_values + 1i*randi(int_max,[1,nnz_fact]);
otherwise
error('invalid scalar type');
end
dense = dense * current_fact;
id_1D = randperm(nb_row*nb_col,nnz_fact);
fact_id_row = mod(id_1D-1,nb_row)+1;
fact_id_col = floor((id_1D-1)/nb_row)+1;
current_fact = sparse(fact_id_row,fact_id_col,fact_values,nb_row,nb_col,nnz_fact);
switch sparsityType
case 'dense'
current_fact=full(current_fact);
......@@ -106,6 +134,9 @@ int_max = 100;
current_fact=sparse(current_fact);
end
dense = dense * full(current_fact);
factors{i}=current_fact;
end
......
......@@ -59,7 +59,7 @@
function test_matlab_faust(factors,expected_F_dense,dim3,copyOptimized)
%function test_matlab_faust(dim1,dim2,dim3,nb_fact)
int_max= 100;
threshold = 10^(-1);
threshold = 0.2;
nb_fact=length(factors);
......@@ -83,11 +83,20 @@ else
scalarType='real';
end
expected_nz = 0;
for i=1:nb_fact
expected_nz = expected_nz + nnz(factors{i});
end
expected_density = expected_nz/(dim1*dim2);
disp('****** TEST MATLAB_FAUST ******* ');
disp([' CONFIG OF THE ' scalarType ' scalar FAUST ']);
disp(['number of row of the Faust : ' int2str(dim1)]);
disp(['number of column of the Faust : ' int2str(dim2)]);
disp(['number of factor of the Faust : ' int2str(nb_fact)]);
disp(['density of the Faust : ' num2str(expected_density)]);
disp('');
disp(['number of column of the matrix that will be multiplied by the Faust : ' int2str(dim3)]);
disp('');
......@@ -190,10 +199,7 @@ disp('Ok');
%% full test
disp('TEST NNZ : ');
expected_nz = 0;
for i=1:nb_fact
expected_nz = expected_nz + nnz(factors{i});
end
nz = nnz(F);
......@@ -228,7 +234,6 @@ disp('Ok');
disp('TEST DENSITY : ');
expected_density = expected_nz / (dim1*dim2);
dens = density(F);
if(dens ~= expected_density)
error('density : invalid value');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment