Mentions légales du service

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

reorganisation/documentation test

parent 1e234533
Branches
Tags
No related merge requests found
Showing
with 582 additions and 411 deletions
......@@ -327,7 +327,10 @@ set(FAUST_DATA_MAT_DIR ${FAUST_MISC_DIR}/data/mat CACHE INTERNAL "")
set(FAUST_SRC_TEST_TIME_COMP_DIR ${FAUST_SRC_TEST_DIR}/runtime_comparison CACHE INTERNAL "")
set(FAUST_SRC_TEST_TOOL_DIR ${FAUST_SRC_TEST_DIR}/tools CACHE INTERNAL "")
set(FAUST_SRC_TEST_SRC_DIR ${FAUST_SRC_TEST_DIR}/src CACHE INTERNAL "")
set(FAUST_SRC_TEST_SRC_CPP_DIR ${FAUST_SRC_TEST_SRC_DIR}/C++/ CACHE INTERNAL "")
set(FAUST_SRC_TEST_SRC_UNIT_DIR ${FAUST_SRC_TEST_SRC_CPP_DIR}/unit/ CACHE INTERNAL "")
set(FAUST_SRC_TEST_SRC_MATLAB_DIR ${FAUST_SRC_TEST_SRC_DIR}/Matlab/ CACHE INTERNAL "")
set(FAUST_SRC_TEST_SRC_PYTHON_DIR ${FAUST_SRC_TEST_SRC_CPP_DIR}/Python/ CACHE INTERNAL "")
###### WRAPPER MATLAB DIRECTORIES ######
......@@ -401,15 +404,16 @@ if(BUILD_WRAPPER_PYTHON)
set(FAUST_PYTHON_TARGET faust_python CACHE INTERNAL "")
endif(BUILD_WRAPPER_PYTHON)
## examples directories including some examples of the use of the library FAuST
set(FAUST_BIN_TEST_DIR ${PROJECT_BINARY_DIR}/run_test CACHE INTERNAL "")
set(FAUST_BIN_TEST_BIN_DIR ${FAUST_BIN_TEST_DIR}/bin CACHE INTERNAL "")
set(FAUST_BIN_TEST_SRC_DIR ${FAUST_BIN_TEST_DIR}/src CACHE INTERNAL "")
set(FAUST_BIN_TEST_TMP_DIR ${FAUST_BIN_TEST_DIR}/tmp CACHE INTERNAL "")
set(FAUST_BIN_TEST_OUTPUT_DIR ${FAUST_BIN_TEST_DIR}/output CACHE INTERNAL "")
set(FAUST_BIN_TEST_FIG_DIR ${FAUST_BIN_TEST_DIR}/fig CACHE INTERNAL "")
set(FAUST_BIN_TEST_TIME_COMPARE_DIR ${FAUST_BIN_TEST_DIR}/runtime_comparison CACHE INTERNAL "")
set(FAUST_BIN_TEST_TOOLS_DIR ${FAUST_BIN_TEST_DIR}/tools CACHE INTERNAL "")
##################################################################
### In the case of GPU preocess
......
# WRAPPER : TESTS EXAMPLES USING THE LIBRARY FAUST WITH A CPU VERSION
message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
......@@ -137,16 +137,15 @@ endif()
####### UNIT TEST ########
set(FAUST_SRC_TEST_SRC_UNIT_DIR ${FAUST_SRC_TEST_SRC_DIR}/unit/ CACHE INTERNAL "")
set(FAUST_BIN_TEST_SRC_UNIT_DIR ${FAUST_BIN_TEST_SRC_DIR}/unit/ CACHE INTERNAL "")
foreach(TEST_FPP float double)
foreach(FILE faust_mult faust_mult_cplx)
configure_file(${FAUST_SRC_TEST_SRC_UNIT_DIR}/${FILE}.cpp.in ${FAUST_BIN_TEST_SRC_UNIT_DIR}/${FILE}_${TEST_FPP}.cpp @ONLY)
configure_file(${FAUST_SRC_TEST_SRC_UNIT_DIR}/${FILE}.cpp.in ${FAUST_BIN_TEST_SRC_DIR}/${FILE}_${TEST_FPP}.cpp @ONLY)
# Generation of the binary files in double and float precision
add_executable(${FILE}_${TEST_FPP} ${FAUST_BIN_TEST_SRC_UNIT_DIR}/${FILE}_${TEST_FPP}.cpp ${FAUST_BIN_TEST_SRC_DIR}/)
add_executable(${FILE}_${TEST_FPP} ${FAUST_BIN_TEST_SRC_DIR}/${FILE}_${TEST_FPP}.cpp ${FAUST_BIN_TEST_SRC_DIR}/)
target_link_libraries(${FILE}_${TEST_FPP} ${FAUST_TARGET} ${MATIO_LIB_FILE} ${HDF5_LIB_FILE} ${OPENBLAS_LIB_FILE})
......@@ -172,12 +171,12 @@ if(MATIO_LIB_FILE AND MATIO_INC_DIR AND BUILD_READ_MAT_FILE) # AND HDF5_LIB_FILE
### list of executable generated in double and simple precision
# hierarchical_fact : test the hierarchical_fact algorithm
# test_palm4MSA : test the palm4MSA algorithm
# multiply_compare_time : time comparison between Faust-vector product and Dense matrix-vector product
# faust_multiplication : time comparison between Faust-vector product and Dense matrix-vector product
foreach(TEST_FPP float double)
foreach(testin hierarchicalFactorization test_palm4MSA faust_multiplication)
# copy CPU files cpp.in to the user's ./src/ directory in float et double precision
configure_file(${FAUST_SRC_TEST_SRC_DIR}/${testin}.cpp.in ${FAUST_BIN_TEST_SRC_DIR}/${testin}_${TEST_FPP}.cpp @ONLY)
configure_file(${FAUST_SRC_TEST_SRC_CPP_DIR}/${testin}.cpp.in ${FAUST_BIN_TEST_SRC_DIR}/${testin}_${TEST_FPP}.cpp @ONLY)
# Generation of the binary files in double and float precision
add_executable(${testin}_${TEST_FPP} ${FAUST_BIN_TEST_SRC_DIR}/${testin}_${TEST_FPP}.cpp ${FAUST_BIN_TEST_SRC_DIR}/ ${FAUST_CMDLINE_TYPE_FORMAT_MAT_SRC_DIR}/faust_init_from_matio.cpp ${FAUST_CMDLINE_TYPE_FORMAT_MAT_SRC_DIR}/faust_init_from_matio_mat.cpp)
......@@ -189,15 +188,9 @@ if(MATIO_LIB_FILE AND MATIO_INC_DIR AND BUILD_READ_MAT_FILE) # AND HDF5_LIB_FILE
endforeach()
endforeach()
#message(STATUS "ALALALLLLLLLLLLL FAUST_INSTALL_BIN=${FAUST_INSTALL_BIN}")
#file(MAKE_DIRECTORY ${FAUST_INSTALL_BIN})
# install(TARGETS hierarchicalFactorization_double hierarchicalFactorization_float test_palm4MSA_double test_palm4MSA_float DESTINATION ${FAUST_INSTALL_BIN} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
# matlab script useful for displaying the result of the multiply_compare_time executable (
configure_file(${FAUST_SRC_TEST_TIME_COMP_DIR}/display_multiply_comptime.m.in ${FAUST_BIN_TEST_TIME_COMPARE_DIR}/display_multiply_comptime.m @ONLY)
#file(MAKE_DIRECTORY ${FAUST_INSTALL_BIN_TIME_COMP})
#install(FILES ${FAUST_BIN_TEST_TIME_COMPARE_DIR}/display_multiply_comptime.m DESTINATION ${FAUST_INSTALL_BIN_TIME_COMP} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE)
###### IN CASE MATIO IS NOT AVAILABLE YOU CAN RUN THE TEST ######
......@@ -212,7 +205,7 @@ if (BUILD_WRAPPER_MATLAB)
foreach(matlabtest hier_fact_test.m generate_Faust_config.m test_matlab_faust.m test_matlab_faust2.m test_matlab_faust_mult.m test_matlab_faust_time.m)
configure_file(${FAUST_SRC_TEST_SRC_DIR}/${matlabtest} ${FAUST_BIN_TEST_BIN_DIR}/${matlabtest} @ONLY)
configure_file(${FAUST_SRC_TEST_SRC_MATLAB_DIR}/${matlabtest} ${FAUST_BIN_TEST_BIN_DIR}/${matlabtest} @ONLY)
endforeach()
endif(BUILD_WRAPPER_MATLAB)
......@@ -282,12 +275,10 @@ if (BUILD_READ_MAT_FILE)
## time comparison between Faust-vector product and Dense matrix-vector product for various configuration ( dimension, RCG , number of factor)
#add_test(NAME MULTIPLY_COMPTIME COMMAND ${FAUST_BIN_TEST_BIN_DIR}/multiply_compare_time_double)
## display the result of MULTIPLY_COMPTIME and save it in folder FAUST_BIN_TEST_FIG_DIR as jpeg image (WARNING must be launched after MULTIPLY_COMPTIME)
#add_test(NAME FIG_MULTIPLY_COMPTIME COMMAND matlab -nodesktop -r "try;addpath('${FAUST_BIN_TEST_TIME_COMPARE_DIR}');display_multiply_comptime('${FAUST_BIN_TEST_OUTPUT_DIR}/multiply_compare_time.mat','${FAUST_BIN_TEST_FIG_DIR}') ; catch ME ; disp('ERROR IN TEST display_multiply_comptime.m Please chek the output to visualize the error. ') ; end ; exit")
#set_tests_properties(FIG_MULTIPLY_COMPTIME PROPERTIES TIMEOUT 300)
endif (BUILD_READ_MAT_FILE)
......
##################################################################
############## README : TEST with CTest ##############
############## of the FAuST project ##############
##################################################################
It's here that all the different test are generated.
Here is tested,
1- C++ code unitary function (cf directory src/C++/unit)
2- C++ code with input as Matlab storing file extension (.mat) (cf directory src/C++/)
3- Matlab wrapper (cf directory src/Matlab)
4- Python wrapper (cf directory src/Python)
5- Cmdline wrapper WARNING this wrapper doesn't work anymore
##################################################################
- I How to add a test ?
In the CMakelist.txt in misc/test/,
just write this :
add_test(NAME myTest COMMAND myExe)
This will add a test named myTest that will execute the myExe
##################################################################
- II How to make a test ?
All the executable return a value,
if it's 0, the test succeeds
else the test fails.
So, make sure you're executable return the corresponding value.
##################################################################
- III How to list the different test available ?
In the build directory,
after configuring, generated, compiled your project you can launch test.
If you are in your build directory,
to list the different test available,
type the following command :
$ ctest -N
--> the ouput of this command should lool like this :
Test #1: MATLAB_FACT_HIER_MEX
Test #2: MATLAB_FACT_HIER_MATLAB
Test #3: MATLAB_FACT_MEG_MEX
Test #4: MATLAB_FACT_MEG_MATLAB
Test #5: MATLAB_FACT_HADAMARD_MEX
Test #6: MATLAB_FACT_HADAMARD_MATLAB
Test #7: MATLAB_DEMO_INSTALL
Test #8: MATLAB_DEMO_BUILD
Test #9: MATLAB_FAUST_CONFIG_REAL1
Test #10: MATLAB_FAUST_CONFIG_REAL2
Test #11: MATLAB_FAUST_CONFIG_REAL3
Test #12: MATLAB_FAUST_CONFIG_REAL4
Test #13: MATLAB_FAUST_CONFIG_CPLX1
Test #14: MATLAB_FAUST_CONFIG_CPLX2
Test #15: MATLAB_FAUST_2
Test #16: MATLAB_FAUST_SPEED
Test #17: UNIT_faust_mult_float
Test #18: UNIT_faust_mult_cplx_float
Test #19: UNIT_faust_mult_double
Test #20: UNIT_faust_mult_cplx_double
Test #21: PYTHON_FAUST
...
Test #48: MATFILE_FACT_MEG_float
Test #49: MATFILE_FACT_MEG_double
Test #50: MATFILE_FACT_MEG_TRANSPOSED_float
Test #51: MATFILE_FACT_MEG_TRANSPOSED_double
--> Commentary on the ouput :
As you can see, the different test are listed by name and id
These test are classified quite easily.
The test whose name begin by MATLAB test the Matlab wrapper.
The test whose name begin by PYTHON test the Python wrapper.
The test whose name begin by UNIT are unitary test (low-level C++ test).
The test whose name begin by MATFILE are C++ test using input data stored in matfile.
The test whose name have the word FACT inside test factorization algorithm.
The test whose name begin by MATLAB_FAUST_CONFIG test the Matlab class Faust with various configuration.
##################################################################
- IV How to run the different test ?
Make sure you are in the build directory
1 - run all the test :
type the following command
$ ctest
2 - run all the test whose name begin by MATLAB_FAUST_CONFIG :
$ ctest -R MATLAB_FAUST_CONFIG
--> the ouput should look like
Test project /home/nbellot/WORK/faust/trunk/devcpp/build
Start 9: MATLAB_FAUST_CONFIG_REAL1
1/6 Test #9: MATLAB_FAUST_CONFIG_REAL1 ........ Passed 2.54 sec
Start 10: MATLAB_FAUST_CONFIG_REAL2
2/6 Test #10: MATLAB_FAUST_CONFIG_REAL2 ........ Passed 2.64 sec
Start 11: MATLAB_FAUST_CONFIG_REAL3
3/6 Test #11: MATLAB_FAUST_CONFIG_REAL3 ........ Passed 2.96 sec
Start 12: MATLAB_FAUST_CONFIG_REAL4
4/6 Test #12: MATLAB_FAUST_CONFIG_REAL4 ........ Passed 2.97 sec
Start 13: MATLAB_FAUST_CONFIG_CPLX1
5/6 Test #13: MATLAB_FAUST_CONFIG_CPLX1 ........ Passed 2.69 sec
Start 14: MATLAB_FAUST_CONFIG_CPLX2
6/6 Test #14: MATLAB_FAUST_CONFIG_CPLX2 ........ Passed 2.65 sec
100% tests passed, 0 tests failed out of 6
3 - run all the test by id :
to run the all the test between test number 1stid and test number lastid
type the following command
$ ctest -I [1stid,lastid]
For example, in our case,
the following command
$ ctest -I [9,14]
will do the same
$ ctest -R MATLAB_FAUST_CONFIG
%% script pour generer des Faust avec un RCG, une Dimension et un nombre de facteur fixe
% lancer l'executable multiply_comptime ensuite pour effectuer les tests de performances
% puis display_multiply_comptime pour afficher les resultats
function gen_artficial_faust(constraint)
%% cas 1
% RCGs = [2 4 6 8 10];
% Dims = [128 256 512];
% nb_facts = [2,4,6];
%% cas 2
RCGs = [2 4 8 16];
Dims = [128 256 512 1024 2048];
nb_facts = [2,4,8,16];
% RCGs = [2 4];
% Dims = [32 64 128];
% nb_facts = [2,4];
nb_test = 50;
% constraint='sp_row';% choix possible 'sp_row' et 'sp_col_'
nRCGS = length(RCGs);
nDims = length(Dims);
nfacts = length(nb_facts);
real_RCGs = zeros(nb_test,nRCGS,nDims,nfacts);
ts_dense = zeros(nb_test,nRCGS,nDims,nfacts);
ts_mex = zeros(nb_test,nRCGS,nDims,nfacts);
ts_random_dense = zeros(nb_test,nRCGS,nDims,nfacts);
opt_calcul = 0;
densite = RCGs.^(-1);
addpath('../build/mex')
addpath('./tools');
if ((strcmp(constraint,'sp') + strcmp(constraint,'sp_row') + strcmp(constraint,'sp_col')) == 0)
error('the constraint parameter must be equal to sp or sp_row or sp_col');
end
for h=1:nfacts
nb_fact=nb_facts(h);
disp(['NB_FACT : ' int2str(nb_fact)]);
for j=1:nDims
dim1=Dims(j);
dim2=dim1;
disp([' Dim : ' int2str(dim1)]);
random_dense_mat = rand(dim1,dim2);
eval(['DMat_Dim_' int2str(dim1) ' = random_dense_mat;']);
fprintf('RCG : ');
for i=1:nRCGS
RCG=RCGs(i);
fprintf('%d ',RCG);
densite_per_fact = densite(i)/nb_fact;
nnz = densite_per_fact*Dims(j)^2;
facts=cell(1,nb_fact);
if (strcmp(constraint,'sp_row'))
nb_elt_per_row = round(dim2*densite_per_fact);
nb_elt = nb_elt_per_row * dim1;
id_i=reshape(repmat((1:dim1),nb_elt_per_row,1),dim1*nb_elt_per_row,1);
id_j=zeros(nb_elt,1);
value=zeros(nb_elt,1);
end
if (strcmp(constraint,'sp_col'))
nb_elt_per_col = round(dim1*densite_per_fact);
nb_elt = nb_elt_per_col * dim2;
id_j=reshape(repmat((1:dim2),nb_elt_per_col,1),dim2*nb_elt_per_col,1);
id_i=zeros(nb_elt,1);
value=zeros(nb_elt,1);
end
for k=1:nb_fact
if (strcmp(constraint,'sp'))
facts{k} = sprand(dim1,dim2,densite_per_fact);
end
if (strcmp(constraint,'sp_row'))
value=rand(nb_elt,1);
for ll=0:dim1-1
id_j(ll*nb_elt_per_row+1:(ll+1)*nb_elt_per_row)=randperm(dim2,nb_elt_per_row)';
end
facts{k}=sparse(id_i,id_j,value,dim1,dim2);
end
if (strcmp(constraint,'sp_col'))
value=rand(nb_elt,1);
for ll=0:dim2-1
id_i(ll*nb_elt_per_col+1:(ll+1)*nb_elt_per_col)=randperm(dim1,nb_elt_per_col)';
end
facts{k}=sparse(id_i,id_j,value,dim1,dim2);
end
end
S_prod = facts{1};
for k=2:nb_fact
S_prod = S_prod * facts{k};
end
S_prod = full(S_prod);
eval(['Faust_nfact_' int2str(nb_fact) '_RCG_' int2str(RCG) '_Dim_' int2str(dim1) ' = facts;']);
if (opt_calcul ~= 0)
fc = Faust(facts);
for k=1:nb_test
v=rand(dim2,1);
%% MEX
tic
w_faust_mex = fc*v; % surcharge de l'operateur * de la class Faust
t_mex = toc;
%% DENSE
w_faust_matlab=v;
tic;
w_matlab = S_prod * v;
t_dense = toc;
%% RANDOM
w_faust_matlab=v;
tic;
w_matlab_random = random_dense_mat * v;
t_random_dense = toc;
ts_mex(k,i,j,h) = t_mex;
ts_dense(k,i,j,h) = t_dense;
ts_random_dense(k,i,j,h) = t_random_dense;
end
end
end
fprintf('\n');
end
end
if (opt_calcul ~= 0)
mean_t_random_dense=squeeze(mean(ts_random_dense));
mean_t_dense=squeeze(mean(ts_dense));
mean_t_mex=squeeze(mean(ts_mex));
rapport_dense = mean_t_random_dense ./ mean_t_dense;
real_RCG = mean_t_dense ./ mean_t_mex;
disp([' comp_dense vs random_dense ']);
for k=1:nfacts
disp( ['nb_fact = ' int2str(nb_facts(k))]);
for i=1:nRCGS
disp(num2str(rapport_dense(i,:,k)));
end
disp('');
end
disp('');
disp('');
disp('');
disp(['real RCG ']);
for i=1:nfacts
disp( ['nb_fact = ' int2str(nb_facts(k))]);
disp(num2str([0 Dims]));
for i=1:nRCGS
disp(num2str([ RCGs(i) real_RCG(i,:,k)]));
end
end
end
disp('sauvegarde des donnees');
save(['data/Faust_example.mat']);
end
clear all;
close all;
filename='cas_hierarchical_prox_sp.mat';
N_FACTS = 3; % Desired number of factors
DIM1=5;
DIM2=20;
DIMS_INTER = round(randi( [min([DIM1+1,DIM2+1]) max([DIM1-1,DIM2-1])] ,[1 ,N_FACTS-1]));
params.nfacts = N_FACTS;
params.niter1 = 5;
params.niter2 = 5;
params.verbose = 1;
params.fact_side = 0;
params.updateway = 0;% parameter are updated from right to left
params.init_lambda = 100; % defaut value equal 1
% M=rand(DIM1,DIM2);
M=zeros(DIM1,DIM2);
M(:)=1:DIM1*DIM2;
params.data=M;
%% Constraints
if (params.fact_side == 0)
for i=2:N_FACTS-1
params.cons{1,i} = {'sp',5,DIMS_INTER(i-1),DIMS_INTER(i)};
params.cons{2,i} = {'sp',(N_FACTS-i)/N_FACTS*DIM1*DIM2,DIMS_INTER(i),DIM2};
end
params.cons{1,1} = {'sp',3,DIM1,DIMS_INTER(1)};
params.cons{2,1} = {'sp',(N_FACTS-1)/N_FACTS*DIM1*DIM2,DIMS_INTER(1),DIM2};
else
for i=N_FACTS-1:-1:2
params.cons{1,N_FACTS-i+1} = {'sp',i*i,DIM1,DIMS_INTER(i-1)};
params.cons{2,N_FACTS-i+1} = {'sp',i,DIMS_INTER(i-1),DIMS_INTER(i)};
end
params.cons{1,1} = {'sp',3,DIM1,DIMS_INTER(N_FACTS-1)};
params.cons{2,1} = {'sp',3,DIMS_INTER(N_FACTS-1),DIM2};
end
[lambda, facts, errors] = hierarchical_fact(params);
%%profile viewer
%%p = profile('info');
%%profsave(p,['comp_normR_profiler FACT' int2str(N_FACTS) 'DIM : ' int2str(DIMS(1)) ' ' int2str(DIMS(end))]) ;
save(filename);
\ No newline at end of file
clear all;
close all;
filename='cas_test5.mat';
N_FACTS = 4; % Desired number of factors
DIM1=5;
DIM2=8;
DIMS_INTER = round(randi( [min([DIM1+1,DIM2+1]) max([DIM1-1,DIM2-1])] ,[1 ,N_FACTS-1]));
params.nfacts = N_FACTS;
params.niter = 200;
params.verbose = 1;
params.updateway = 0;% parameter are updated from right to left
params.init_lambda = 1; % defaut value equal 1
M=rand(DIM1,DIM2);
params.data=M;
% Constraints
for i=2:N_FACTS-1
if(mod(i,2)==0)
name_const = 'sp';
else
name_const = 'sppos'
end
params.cons{1,i} = {name_const,min(DIMS_INTER(i-1:i)),DIMS_INTER(i-1),DIMS_INTER(i)};
params.init_facts{1,i} = eye(DIMS_INTER(i-1),DIMS_INTER(i));
end
params.cons{1,1} = {'sp',min([DIMS_INTER(1),DIM1]),DIM1,DIMS_INTER(1)};
params.init_facts{1,1} = eye(DIM1,DIMS_INTER(1));
params.cons{1,N_FACTS} = {'sp',min([DIMS_INTER(end),DIM2]),DIMS_INTER(N_FACTS-1),DIM2};
params.init_facts{1,N_FACTS} = eye(DIMS_INTER(end),DIM2);
[lambda, facts] = palm4MSA(params);
%%profile viewer
%%p = profile('info');
%%profsave(p,['comp_normR_profiler FACT' int2str(N_FACTS) 'DIM : ' int2str(DIMS(1)) ' ' int2str(DIMS(end))]) ;
save(filename);
%% this function displays the resulting C++ computed times between the 2 different
% multiplication (faust vs dense matrix) for different RCG, dimension and
% matrix
%% WARNING this script must be run after @FAUST_SRC_TEST_DIR@/gen_artificial_faust.m
% which store some Faust::Transform example with different dimensions RCG and
% number of factors in
% after run the executable
% @FAUST_BIN_TEST_BIN_DIR@/multiply_compare_time that will do some time
% comparison between dense mat-vector product and faust-vector product
%
% example of inputfile and outputdir
%inputfile='@FAUST_BIN_TEST_OUTPUT_DIR@/multiply_compare_time.mat';
%outputdir='@FAUST_BIN_TEST_FIG_DIR@';
function display_multiply_comptime(inputfile,outputdir)
close all;
load(inputfile);
nDIMS=length(DIMS);
nRCGS=length(RCGS);
nNB_FACTS=length(NB_FACTS);
if ((NB_RUN*nRCGS)~=size(tdense,1)) | ((NB_RUN*nRCGS)~=size(tfaust,1)) | ((nDIMS*nNB_FACTS)~=size(tdense,2)) | ((nDIMS*nNB_FACTS)~=size(tfaust,2))
error('invalid input file');
end
%% average the multiplication according to the number of run
tdense=reshape(tdense,NB_RUN*nRCGS,nDIMS,nNB_FACTS);
tdense=mean(tdense,1);
tdense=mean(tdense,3);
mean_tdense=repmat(tdense,nRCGS,1,nNB_FACTS);
tfaust=reshape(tfaust,NB_RUN,nRCGS,nDIMS,nNB_FACTS);
mean_tfaust=squeeze(mean(tfaust,1));
tdense=mean(tdense,3);
mean_tdense=repmat(tdense,nRCGS,1,nNB_FACTS);
%% plot the time computed in logscale with a fix number of factor in a given figure
% in each figure we have in x-axis the log2(dimension) of the square matrix
% in y-axis the time
% all time for faust multiplication with different RCG (density)
% and the time for dense matrix multiplication are plotted
legend_curve=cell(1,nRCGS+1);
thickness_curve = 2;
%% hold the different figure are in the same box (scale)
ymin=min([min(mean_tdense(:)),min(mean_tfaust(:))]);
ymax=max([max(mean_tdense(:)),max(mean_tfaust(:))]);
for nfact=1:nNB_FACTS
fighandle=figure;
for k=nRCGS:-1:1
semilogy(log2(DIMS),mean_tfaust(k,:,nfact),'LineWidth',thickness_curve);
legend_curve{k}=['Faust RCG ' num2str(RCGS(nRCGS-k+1))];
hold on;
end
%LA boucle fait remettre les compteurs a zero, que ce soit des
%numero de courbes ou des couleurs, c'est pourquoi il faut la
%mettre en premier et
%forcer la couleur du dense (voire ci dessous).
semilogy(log2(DIMS),squeeze(mean_tdense(1,:,:)),'Color',[0 0.8 0.8],'LineWidth',thickness_curve);
legend_curve{nRCGS+1}=['Dense '];
% legend the figure,title, font ...
grid on;
axis([log2(DIMS(1)) log2(DIMS(end)) ymin ymax]);
legend(legend_curve{:},'Location', 'SouthEast');
title (['Dense multiplication vs Faust multiplication (nb factor : ' ,int2str(NB_FACTS(nfact)), ' )' ] );
xlabel('log2(Dimension)');
ylabel('Time');
set(gca,'FontWeight','Bold');
% save the current figure
saveas(fighandle,[outputdir filesep 'fig_FAUST_nbfact_' int2str(NB_FACTS(nfact)) '.jpeg']);
end
disp(strcat('The figures are generated in directory : ', outputdir));
/****************************************************************************/
/* Description: */
/* unitary test for testing multiplication by faust with real scalar */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.gforge.inria.fr> */
/* */
/* License: */
/* Copyright (2016): Nicolas Bellot, Adrien Leman, Thomas Gautrais, */
/* Luc Le Magoarou, Remi Gribonval */
/* INRIA Rennes, FRANCE */
/* http://www.inria.fr/ */
/* */
/* The FAuST Toolbox is distributed under the terms of the GNU Affero */
/* General Public License. */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Affero General Public License as */
/* published by the Free Software Foundation. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* See the GNU Affero General Public License for more details. */
/* */
/* You should have received a copy of the GNU Affero General Public */
/* License along with this program. */
/* If not, see <http://www.gnu.org/licenses/>. */
/* */
/* Contacts: */
/* Nicolas Bellot : nicolas.bellot@inria.fr */
/* Adrien Leman : adrien.leman@inria.fr */
/* Thomas Gautrais : thomas.gautrais@inria.fr */
/* Luc Le Magoarou : luc.le-magoarou@inria.fr */
/* Remi Gribonval : remi.gribonval@inria.fr */
/* */
/* References: */
/* [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse */
/* approximations of matrices and applications", Journal of Selected */
/* Topics in Signal Processing, 2016. */
/* <https://hal.archives-ouvertes.fr/hal-01167948v1> */
/****************************************************************************/
#include "faust_MatSparse.h"
#include "faust_HierarchicalFact.h"
#include "faust_Timer.h"
#include "faust_Transform.h"
#include <string>
#include <sstream>
#include "faust_BlasHandle.h"
#include "faust_SpBlasHandle.h"
#include <iostream>
#include <iomanip>
/** \brief unitary test for testing multiplication by faust
*/
typedef @TEST_FPP@ FPP;
//using namespace Faust;
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
int dim1 = 3;
int dim2 = 4;
int dim3 = 2;
int nb_factor = 3;
/* initilisation of the factors of the Faust */
// factor 1
Faust::MatDense<FPP,Cpu> fact1(dim1,dim2);
for (int j=0;j < dim1*dim2; j ++)
{
fact1[j]= FPP(j*j);
};
// factor 2
Faust::MatDense<FPP,Cpu> fact2(dim2,dim2);
for (int i=0;i< dim2; i++)
{
for (int j=0;j< dim2; j++)
{
fact2[i*dim2+j]= FPP(i+1);
}
}
// factor 3
Faust::MatDense<FPP,Cpu> fact3_dense(dim2,dim2);
for (int i=0;i< dim2; i++)
{
for (int j=0;j< dim2; j++)
{
fact3_dense[i*dim2+j]= FPP(i+2);
}
}
Faust::MatSparse<FPP,Cpu> fact3_sparse(fact3_dense);
std::cout<<"fact1 value"<<std::endl;
fact1.Display();
std::cout<<"fact2 value"<<std::endl;
fact2.Display();
std::cout<<"fact3 value"<<std::endl;
fact3_dense.Display();
/* initialisation of the list of factors of the Faust */
vector<Faust::MatGeneric<FPP,Cpu> *> list_fact;
list_fact.resize(nb_factor);
list_fact[0]=fact1.Clone();
list_fact[1]=fact2.Clone();
list_fact[2]=fact3_sparse.Clone();
/* initialisation of the Faust (Transform) */
std::cout<<"init Faust "<<std::endl;
bool ispOtimized = false;
Faust::Transform<FPP,Cpu> F(list_fact,1.0,ispOtimized);
F.Display();
if (!F.isReal())
{
std::cerr<<"F.isreal() invalid value, F must be made of real scalar "<<std::endl;
exit(EXIT_FAILURE);
}
int nbRowF = F.getNbRow();
int nbColF = F.getNbCol();
if((nbRowF != dim1) || (nbColF != dim2))
{
std::cerr<<"invalid dimension of F "<<std::endl;
exit(EXIT_FAILURE);
}
std::cout<<"init matrix/vec that will be multiplied "<<std::endl;
Faust::MatDense<FPP,Cpu> identity(nbColF);
for (int i = 0;i<nbColF;i++) identity[i]=FPP(0.0);
for (int i = 0;i<nbColF;i++) identity[i*nbColF+i]=FPP(1.0);
Faust::Vect<FPP,Cpu> vec(nbColF);
for (int i = 0;i<nbColF;i++) vec[i]=FPP(i*i);
// F_dense = F * identity
std::cout<<"F_dense = F * identity "<<std::endl;
Faust::MatDense<FPP,Cpu> F_dense_mult = F.multiply(identity,'N');
if ( (F_dense_mult.getNbRow() != nbRowF) || (F_dense_mult.getNbCol() != nbColF) )
{
std::cerr<<"F size ("<<F_dense_mult.getNbRow()<<","<<F_dense_mult.getNbCol()<<")"<<std::endl;
std::cerr<<"F size expected ("<<nbRowF<<","<<nbColF<<")"<<std::endl;
std::cerr<<"error : invalid dimension of F_dense_mult "<<std::endl;
exit(EXIT_FAILURE);
}
// F_prod must be equal to F_dense
std::cout<<"F_prod = F.get_product"<<std::endl;
Faust::MatDense<FPP,Cpu> F_prod=F.get_product();
if ( (F_prod.getNbRow() != nbRowF) || (F_prod.getNbCol() != nbColF) )
{
std::cerr<<"error : invalid dimension of F_prod "<<std::endl;
exit(EXIT_FAILURE);
}
for (int i=0;i<nbRowF*nbColF;i++)
{
if (F_prod[i] != F_dense_mult[i])
{
std::cerr<<"error : F_prod != F_dense_mult "<<std::endl;
exit(EXIT_FAILURE);
}
}
// F multiply with vec
std::cout<<"F_vec = F * vec "<<std::endl;
Faust::Vect<FPP,Cpu> F_vec = F.multiply(vec,'N');
return 0;
}
/****************************************************************************/
/* Description: */
/* unitary test for testing multiplication by faust with complex scalar */
/* */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.gforge.inria.fr> */
/* */
/* License: */
/* Copyright (2016): Nicolas Bellot, Adrien Leman, Thomas Gautrais, */
/* Luc Le Magoarou, Remi Gribonval */
/* INRIA Rennes, FRANCE */
/* http://www.inria.fr/ */
/* */
/* The FAuST Toolbox is distributed under the terms of the GNU Affero */
/* General Public License. */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Affero General Public License as */
/* published by the Free Software Foundation. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* See the GNU Affero General Public License for more details. */
/* */
/* You should have received a copy of the GNU Affero General Public */
/* License along with this program. */
/* If not, see <http://www.gnu.org/licenses/>. */
/* */
/* Contacts: */
/* Nicolas Bellot : nicolas.bellot@inria.fr */
/* Adrien Leman : adrien.leman@inria.fr */
/* Thomas Gautrais : thomas.gautrais@inria.fr */
/* Luc Le Magoarou : luc.le-magoarou@inria.fr */
/* Remi Gribonval : remi.gribonval@inria.fr */
/* */
/* References: */
/* [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse */
/* approximations of matrices and applications", Journal of Selected */
/* Topics in Signal Processing, 2016. */
/* <https://hal.archives-ouvertes.fr/hal-01167948v1> */
/****************************************************************************/
#include "faust_MatSparse.h"
#include "faust_HierarchicalFact.h"
#include "faust_Timer.h"
#include "faust_Transform.h"
#include <string>
#include <sstream>
#include "faust_BlasHandle.h"
#include "faust_SpBlasHandle.h"
#include <iostream>
#include <iomanip>
/** \brief unitary test for testing multiplication by faust
*/
typedef @TEST_FPP@ FPP;
typedef std::complex<FPP> CPX;
//using namespace Faust;
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
int dim1 = 3;
int dim2 = 4;
int dim3 = 2;
int nb_factor = 3;
/* initilisation of the factors of the Faust */
// factor 1
Faust::MatDense<CPX,Cpu> fact1(dim1,dim2);
for (int j=0;j < dim1*dim2; j ++)
{
fact1[j]= CPX(j,j*j);
};
// factor 2
Faust::MatDense<CPX,Cpu> fact2(dim2,dim2);
for (int i=0;i< dim2; i++)
{
for (int j=0;j< dim2; j++)
{
fact2[i*dim2+j]= CPX(i+1,-i+1);
}
}
// factor 3
Faust::MatDense<CPX,Cpu> fact3_dense(dim2,dim2);
for (int i=0;i< dim2; i++)
{
for (int j=0;j< dim2; j++)
{
fact3_dense[i*dim2+j]= CPX(i+2,-i+2);
}
}
Faust::MatSparse<CPX,Cpu> fact3_sparse(fact3_dense);
std::cout<<"fact1 value"<<std::endl;
fact1.Display();
std::cout<<"fact2 value"<<std::endl;
fact2.Display();
std::cout<<"fact3 value"<<std::endl;
fact3_dense.Display();
/* initialisation of the list of factors of the Faust */
vector<Faust::MatGeneric<CPX,Cpu> *> list_fact;
list_fact.resize(nb_factor);
list_fact[0]=fact1.Clone();
list_fact[1]=fact2.Clone();
list_fact[2]=fact3_sparse.Clone();
/* initialisation of the Faust (Transform) */
std::cout<<"init Faust "<<std::endl;
bool ispOtimized = false;
Faust::Transform<CPX,Cpu> F(list_fact,1.0,ispOtimized);
F.Display();
if (F.isReal())
{
std::cerr<<"F.isreal() invalid value, F must be complex "<<std::endl;
exit(EXIT_FAILURE);
}
int nbRowF = F.getNbRow();
int nbColF = F.getNbCol();
if((nbRowF != dim1) || (nbColF != dim2))
{
std::cerr<<"invalid dimension of F "<<std::endl;
exit(EXIT_FAILURE);
}
std::cout<<"init matrix/vec that will be multiplied "<<std::endl;
Faust::MatDense<CPX,Cpu> identity(nbColF);
for (int i = 0;i<nbColF;i++) identity[i]=CPX(0.0);
for (int i = 0;i<nbColF;i++) identity[i*nbColF+i]=CPX(1.0);
Faust::Vect<CPX,Cpu> vec(nbColF);
for (int i = 0;i<nbColF;i++) vec[i]=CPX(i,i*i);
// F_dense = F * identity
std::cout<<"F_dense = F * identity "<<std::endl;
Faust::MatDense<CPX,Cpu> F_dense_mult = F.multiply(identity,'N');
if ( (F_dense_mult.getNbRow() != nbRowF) || (F_dense_mult.getNbCol() != nbColF) )
{
std::cerr<<"F size ("<<F_dense_mult.getNbRow()<<","<<F_dense_mult.getNbCol()<<")"<<std::endl;
std::cerr<<"F size expected ("<<nbRowF<<","<<nbColF<<")"<<std::endl;
std::cerr<<"error : invalid dimension of F_dense_mult "<<std::endl;
exit(EXIT_FAILURE);
}
// F_prod must be equal to F_dense
std::cout<<"F_prod = F.get_product"<<std::endl;
Faust::MatDense<CPX,Cpu> F_prod=F.get_product();
if ( (F_prod.getNbRow() != nbRowF) || (F_prod.getNbCol() != nbColF) )
{
std::cerr<<"error : invalid dimension of F_prod "<<std::endl;
exit(EXIT_FAILURE);
}
for (int i=0;i<nbRowF*nbColF;i++)
{
if (F_prod[i] != F_dense_mult[i])
{
std::cerr<<"error : F_prod != F_dense_mult "<<std::endl;
exit(EXIT_FAILURE);
}
}
// F multiply with vec
std::cout<<"F_vec = F * vec "<<std::endl;
Faust::Vect<CPX,Cpu> F_vec = F.multiply(vec,'N');
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment