Mentions légales du service

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

test matlab robustification

parent f01497b8
Branches
Tags
No related merge requests found
...@@ -57,9 +57,9 @@ endif(MATIO_LIB_FILE AND MATIO_INC_DIR AND FAUST_USE_MATIO) ...@@ -57,9 +57,9 @@ endif(MATIO_LIB_FILE AND MATIO_INC_DIR AND FAUST_USE_MATIO)
if (BUILD_MATLAB_MEX_FILES) if (BUILD_MATLAB_MEX_FILES)
configure_file(${FAUST_SRC_TEST_TOOL_DIR}/set_path.m.in ${FAUST_BIN_TEST_TOOLS_DIR}/set_path.m @ONLY) configure_file(${FAUST_SRC_TEST_TOOL_DIR}/set_path.m.in ${FAUST_BIN_TEST_TOOLS_DIR}/set_path.m @ONLY)
configure_file(${FAUST_SRC_TEST_TOOL_DIR}/launch_hierarchical_fact.m ${FAUST_BIN_TEST_TOOLS_DIR}/launch_hierarchical_fact.m COPYONLY)
foreach(matlabtest hier_fact.m MEG_fact.m)
foreach(matlabtest hier_fact_test.m)
configure_file(${FAUST_SRC_TEST_SRC_DIR}/${matlabtest} ${FAUST_BIN_TEST_BIN_DIR}/${matlabtest} COPYONLY) configure_file(${FAUST_SRC_TEST_SRC_DIR}/${matlabtest} ${FAUST_BIN_TEST_BIN_DIR}/${matlabtest} COPYONLY)
endforeach() endforeach()
endif(BUILD_MATLAB_MEX_FILES) endif(BUILD_MATLAB_MEX_FILES)
...@@ -73,7 +73,7 @@ endif(BUILD_MATLAB_MEX_FILES) ...@@ -73,7 +73,7 @@ endif(BUILD_MATLAB_MEX_FILES)
############################################################################## ##############################################################################
# Critical time, which fixe the limit time of the process # Critical time, which fixe the limit time of the process
set(TIMEOUT_MEG 7200) set(TIMEOUT_MEG 7200)
set(TIMEOUT_COMP 3000) set(TIMEOUT_COMP 10)
# MATLAB input format # MATLAB input format
...@@ -124,16 +124,19 @@ endif(FAUST_USE_XML) ...@@ -124,16 +124,19 @@ endif(FAUST_USE_XML)
if(BUILD_MATLAB_MEX_FILES) if(BUILD_MATLAB_MEX_FILES)
#add_test(NAME FAUST_HIER_MEX COMMAND matlab -nojvm -nodisplay -r ${FAUST_BIN_TEST_BIN_DIR}/hier_fact.m;exit) #add_test(NAME FAUST_HIER_MEX COMMAND matlab -nojvm -nodisplay -r ${FAUST_BIN_TEST_BIN_DIR}/hier_fact.m;exit)
# on ajoute les path bin et tools qui sont utilisés pour le script matlab. # on ajoute les path bin et tools qui sont utilisés pour le script matlab.
add_test(NAME FAUST_HIER_MEX COMMAND matlab -nojvm -r "try;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');hier_fact(9400,10); catch ME ; disp('ERROR IN TEST hier_fact.m Please chek the output to visualize the error. '); end ; exit" ) # add_test(NAME FAUST_HIER_MEX COMMAND matlab -nojvm -r "try;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');hier_fact(9400,10); catch ME ; disp('ERROR IN TEST hier_fact.m Please chek the output to visualize the error. '); end ; exit" )
#add_test(NAME FAUST_MEG_MEX COMMAND matlab -nojvm -r "try;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');MEG_fact;end;exit" ) add_test(NAME FAUST_HIER_MEX COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;hier_fact_test('config_compared_hierarchical_fact',9402,1); catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)" )
add_test(NAME FAUST_MEG_MEX COMMAND matlab -nojvm -r "try;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');MEG_fact(22450,100); catch ME ; disp('ERROR IN TEST MEG_fact.m Please chek the output to visualize the error. '); end; exit" ) #add_test(NAME FAUST_MEG_MEX COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');MEG_fact(22450,100); catch ME ; disp('ERROR IN TEST MEG_fact.m Please chek the output to visualize the error. '); end; exit" )
add_test(NAME FAUST_MEG_MEX COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;hier_fact_test('config_MEG',22450,100);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME FAUST_HADAMARD_MEX COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;hier_fact_test('config_HADAMARD',5941,1);catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
# limit the time of the process in case of bug... # limit the time of the process in case of bug...
#CTEST_FULL_OUTPUT #CTEST_FULL_OUTPUT
set_tests_properties(FAUST_HIER_MEX PROPERTIES TIMEOUT ${TIMEOUT_COMP}) set_tests_properties(FAUST_HIER_MEX FAUST_HADAMARD_MEX PROPERTIES TIMEOUT 30)
set_tests_properties(FAUST_MEG_MEX PROPERTIES TIMEOUT ${TIMEOUT_MEG}) set_tests_properties(FAUST_MEG_MEX PROPERTIES TIMEOUT ${TIMEOUT_MEG})
endif() endif()
......
%% test the mexhierarchical_fact function in the MEG configuration
%addpath(['..' filesep 'tools']);
%set_path;
%load config_MEG;
%[mexlambda,mexfact,fc]=launch_hierarchical_fact(params);
function [testPass]=MEG_fact(expectedLambda, expectedLambdaPrecision)
addpath(['..' filesep 'tools']);
set_path;
load config_MEG;
[mexlambda,mexfact,fc]=launch_hierarchical_fact(params);
if (mexlambda >= (expectedLambda - expectedLambdaPrecision) && (mexlambda <= (expectedLambda + expectedLambdaPrecision)) )
testPass=0; % le résultats est OK
disp('');
disp('Test is successful');
else
testPass=1; % le resutat n'est pas bon.
disp('');
disp('Test is FAILED !!!');
exit (FAILURE);
end
\ No newline at end of file
%% test the mexhierarchical_fact function in the hier fact configuration
%
% addpath(['..' filesep 'tools']);
% set_path;
%
% load config_compared_hierarchical_fact;
% [mexlambda,mexfact,fc]=launch_hierarchical_fact(params);
function [testPass]=hier_fact(expectedLambda, expectedLambdaPrecision)
addpath(['..' filesep 'tools']);
set_path;
load config_compared_hierarchical_fact;
[mexlambda,mexfact,fc]=launch_hierarchical_fact(params);
if (mexlambda >= (expectedLambda - expectedLambdaPrecision) && (mexlambda <= (expectedLambda + expectedLambdaPrecision)) )
testPass=0; % le résultats est OK
disp('');
disp('Test is successful');
else
testPass=1; % le resutat n'est pas bon.
disp('');
disp('Test is NOT successful');
exit (FAILURE);
end
%% launch the mexfunction mexhierarchical_fact and make some time comparison %% test the mexhierarchical_fact function in the configuration described in
function [mexLambda,mexfact,fc]=launch_mexhierarchical_fact(params) % the file paramsfile
function hier_fact_test(paramsfile,expectedLambda, expectedLambdaPrecision)
% load the hierarchical_fact configuration
[mexlambda,mexfact]=mexHierarchical_fact(params); load(paramsfile);
disp(['MEX LAMBDA ' num2str(mexlambda)]);
[mexlambda,mexfact]=mexHierarchical_fact(params);
disp(['lambda value : ' num2str(mexlambda)]);
mexfact{1}=mexlambda*mexfact{1}; if (abs(mexlambda - expectedLambda) > expectedLambdaPrecision)
fc=matlab_faust(mexfact); disp('');
mex_error = norm(params.data - get_product(fc));
disp([ 'expected lamba value : ' int2str(expectedLambda) ' in the precision of ' int2str(expectedLambdaPrecision) ]);
disp(['relative error : ' num2str(mex_error)]); error('invalid lambda value');
end
%% speed-up test for multiplication with a vector
disp('*** product data matrix-vector vs product faust-vector ***');
nbiter = 100;
dense_mat = params.data;
[nl,nc]=size(dense_mat);
y_faust=zeros(nl,1); mexfact{1}=mexlambda*mexfact{1};
y_dense=zeros(nl,1); fc=matlab_faust(mexfact);
tps_dense=zeros(nbiter,1); mex_error = norm(params.data - get_product(fc));
tps_faust=zeros(nbiter,1);
disp(['relative error : ' num2str(mex_error)]);
for i=1:nbiter
x=rand(nc,1);
tic %% speed-up test for multiplication with a vector
y_faust = fc*x; disp('*** product data matrix-vector vs product faust-vector ***');
tps_faust=toc; nbiter = 100;
dense_mat = params.data;
tic [nl,nc]=size(dense_mat);
y_dense = dense_mat*x; y_faust=zeros(nl,1);
tps_dense=toc; y_dense=zeros(nl,1);
end tps_dense=zeros(nbiter,1);
tps_faust=zeros(nbiter,1);
tps_dense=mean(tps_dense); for i=1:nbiter
tps_faust=mean(tps_faust); x=rand(nc,1);
speed_up = tps_dense/tps_faust;
disp(['dense time : ' num2str(tps_dense) ' faust time : ' num2str(tps_faust)]); tic
disp(['speed_up : ' num2str(speed_up)]); y_faust = fc*x;
tps_faust=toc;
tic
y_dense = dense_mat*x;
end tps_dense=toc;
end
tps_dense=mean(tps_dense);
tps_faust=mean(tps_faust);
speed_up = tps_dense/tps_faust;
disp(['dense time : ' num2str(tps_dense) ' faust time : ' num2str(tps_faust)]);
disp(['speed_up : ' num2str(speed_up)]);
%% launch the mexfunction mexhierarchical_fact
%% and makes time comparison between faust and data matrix multiplication with vector
function [mexlambda,mexfact,fc]=mexhierarchical_fact(params)
[mexlambda,mexfact]=mexHierarchical_fact(params);
disp(['MEX LAMBDA ' num2str(mexlambda)]);
%% launch the same algorithm with the Luc's function
% [lambda,fact]=hierarchical_fact(params);
% disp([' LAMBDA ' num2str(lambda) ' MEX_LAMBDA ' num2str(mexlambda)]);
% sum_coeff = 0;
% threshold = 0.00001;
% disp('\n\n COMPARAISON ');
% for i=1:params.nfacts
% comp=abs(mexfact{i} - fact{i})> threshold;
% nb_coeff_diff = sum(comp(:));
% disp([int2str(i) ' nb_coeff diff : ' int2str(nb_coeff_diff)]);
% sum_coeff = nb_coeff_diff + sum_coeff;
%
% end
% disp([' nb coeff different ' int2str(sum_coeff)]);
%
% mex_error = norm(params.data- lambda*dvp(fact));
mexfact{1}=mexlambda*mexfact{1};
fc=matlab_faust(mexfact);
mex_error = norm(params.data - get_product(fc));
disp(['relative error : ' num2str(mex_error)]);
%% speed-up test for multiplication with a vector
disp('*** product data matrix-vector vs product faust-vector ***');
nbiter = 100;
dense_mat = params.data;
[nl,nc]=size(dense_mat);
y_faust=zeros(nl,1);
y_dense=zeros(nl,1);
tps_dense=zeros(nbiter,1);
tps_faust=zeros(nbiter,1);
for i=1:nbiter
x=rand(nc,1);
tic
y_faust = fc*x;
tps_faust=toc;
tic
y_dense = dense_mat*x;
tps_dense=toc;
end
tps_dense=mean(tps_dense);
tps_faust=mean(tps_faust);
speed_up = tps_dense/tps_faust;
disp(['dense time : ' num2str(tps_dense) ' faust time : ' num2str(tps_faust)]);
disp(['speed_up : ' num2str(speed_up)]);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment