Mentions légales du service

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

nouveau test matlab

parent 2bdae3fc
Branches
Tags
No related merge requests found
...@@ -59,7 +59,7 @@ if (BUILD_MATLAB_MEX_FILES) ...@@ -59,7 +59,7 @@ 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)
foreach(matlabtest hier_fact_test.m) foreach(matlabtest hier_fact_test.m test_matlab_faust.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)
...@@ -126,6 +126,7 @@ if(BUILD_MATLAB_MEX_FILES) ...@@ -126,6 +126,7 @@ if(BUILD_MATLAB_MEX_FILES)
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_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)") 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)")
add_test(NAME DEMO_MATLAB COMMAND matlab -nodesktop -r "try;testpass=0;addpath('${FAUST_MATLAB_INSTALL_DIR}');setup_FAUST;run_all_demo;catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)") add_test(NAME DEMO_MATLAB COMMAND matlab -nodesktop -r "try;testpass=0;addpath('${FAUST_MATLAB_INSTALL_DIR}');setup_FAUST;run_all_demo;catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
add_test(NAME MATLAB_FAUST COMMAND matlab -nojvm -r "try;testpass=0;addpath('${FAUST_BIN_TEST_BIN_DIR}','${FAUST_BIN_TEST_TOOLS_DIR}');set_path;test_matlab_faust;catch ME ;testpass=-1;disp(getReport(ME)); end ; exit(testpass)")
......
%% Description test_faust_transform
% This script tests the malab_faust class, i.e the different method
% overloaded for a faust (constructor, size, mtimes, mtimes_trans ...)
nb_fact = 3;
dim1 = 5;
dim2 = 3;
dim3 = 10;
int_max= 100;
threshold = 10^(-15); % equality test
%% creation du faust
factors=cell(1,nb_fact);
factors{1}=double(randi(int_max,dim1,dim2));
for i=2:nb_fact
factors{i}=double(randi(int_max,dim2,dim2));
end
F = matlab_faust(factors);
%% size test
[dim1_test,dim2_test]=size(F);
if ((dim1_test ~= dim1) | (dim2_test ~= dim2))
error(['size : invalid output dimension']);
end
dim1_test1=size(F,1);
dim2_test1=size(F,2);
if ((dim1_test1 ~= dim1) | (dim2_test1 ~= dim2))
error(['size : invalid output dimension']);
end
%% get_product test
F_dense= get_product(F);
[dim1_dense,dim2_dense]=size(F_dense);
if((dim1_dense ~= dim1) | (dim2_dense ~= dim2))
error('get_product : invalid dimension');
end
%% transpose test
F_trans = F';
[dim1_trans,dim2_trans]=size(F_trans);
F_dense_trans=get_product(F_trans);
if ((dim1_trans ~= dim2) | (dim2_trans ~= dim1))
error(['transpose : invalid dimension']);
end
F_dense_trans=get_product(F_trans);
if(norm(F_dense' - F_dense_trans)>threshold)
error(['transpose : invalid value']);
end
%% test faust multiplication with vector
x=zeros(dim2,1);
x(:)=1:dim2;
x_trans=zeros(dim1,1);
x_trans(:)=1:dim1;
y_expected = F_dense*x;
y_expected_trans = F_dense'*x_trans;
y_star = F*x;
if (y_expected ~= y_star)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
end
y_star_trans = F'*x_trans;
if (y_expected_trans~= y_star_trans)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
end
y_mtimes_trans = mtimes_trans(F,x_trans,'T');
if (y_expected_trans ~= y_mtimes_trans)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
end
y_mtimes = mtimes_trans(F,x,'N');
if (y_expected ~= y_mtimes)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
end
%% test multiplication with matrix
X=zeros(dim2,dim3);
X(:)=1:dim2*dim3;
X_trans=zeros(dim1,dim3);
X_trans(:)=1:dim1*dim3;
Y_expected = F_dense*X;
Y_expected_trans = F_dense'*X_trans;
Y_star = F*X;
if (Y_expected ~= Y_star)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
end
Y_star_trans = F'*X_trans;
if (Y_expected_trans~= Y_star_trans)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
end
Y_mtimes_trans = mtimes_trans(F,X_trans,'T');
if (Y_expected_trans ~= Y_mtimes_trans)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
end
Y_mtimes = mtimes_trans(F,X,'N');
if (Y_expected ~= Y_mtimes)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
end
%class MATLAB_FAUST %class MATLAB_FAUST
% representing a given dense matrix by a product of sparse matrix (i.e faust) % representing a given dense matrix by a product of sparse matrix (i.e faust)
% in order to speed-up multiplication by this matrix, % in order to speed-up multiplication by this matrix,
% matlab wrapper class implemented in C++ % matlab wrapper class implemented in C++
% %
% For more information on the FAuST Project, please visit the website of % For more information on the FAuST Project, please visit the website of
% the project : <http://faust.gforge.inria.fr> % the project : <http://faust.gforge.inria.fr>
classdef matlab_faust < handle classdef matlab_faust < handle
properties (SetAccess = private, Hidden = true) properties (SetAccess = private, Hidden = true)
objectHandle; % Handle to the underlying C++ class instance objectHandle; % Handle to the underlying C++ class instance
end end
methods methods
%% Constructor - Create a new C++ class instance %% Constructor - Create a new C++ class instance
function this = matlab_faust(varargin) function this = matlab_faust(varargin)
% Constructor - build a faust from a cell array of matrix and a scalar (optional) % Constructor - build a faust from a cell array of matrix and a scalar (optional)
% 1st input : 1D cell array of matrix (sparse or dense) % 1st input : 1D cell array of matrix (sparse or dense)
% 2nd input : (optional) multiplicative scalar % 2nd input : (optional) multiplicative scalar
this.objectHandle = mexFaust('new',varargin{:}); this.objectHandle = mexFaust('new',varargin{:});
end end
%% Destructor - Destroy the C++ class instance %% Destructor - Destroy the C++ class instance
function delete(this) function delete(this)
% destructor delete the faust % destructor delete the faust
mexFaust('delete', this.objectHandle); mexFaust('delete', this.objectHandle);
end end
%% Multiplication faust-vector or faust-matrix %% Multiplication faust-vector or faust-matrix
function varargout = mtimes(this, varargin) function varargout = mtimes(this, varargin)
% mtimes - overloading of the matlab multiplication (*) function, compatible with matlab matrix and vector % mtimes - overloading of the matlab multiplication (*) function, compatible with matlab matrix and vector
[varargout{1:nargout}] = mexFaust('multiply', this.objectHandle, varargin{:},'N'); [varargout{1:nargout}] = mexFaust('multiply', this.objectHandle, varargin{:},'N');
end end
%% Multiplication by a faust or its transpose %% Multiplication by a faust or its transpose
% if trans = 'N' multiplication by faust % if trans = 'N' multiplication by faust
% if trans = 'T' multiplication the transpose of a faust % if trans = 'T' multiplication the transpose of a faust
function varargout = mtimes_trans(this,varargin) function varargout = mtimes_trans(this,varargin)
[varargout{1:nargout}] = mexFaust('multiply', this.objectHandle,varargin{:}); [varargout{1:nargout}] = mexFaust('multiply', this.objectHandle,varargin{:});
end
end
%% Evaluate the product of a faust_core
function varargout = get_product(this) %% Evaluate the product of a faust_core
% get_product - compute the dense matrix equivalent to the faust (the product of sparse matrix) function varargout = get_product(this)
[varargout{1:nargout}]=mexFaust('get_product',this.objectHandle); % get_product - compute the dense matrix equivalent to the faust (the product of sparse matrix)
end [varargout{1:nargout}]=mexFaust('get_product',this.objectHandle);
%% Transpose operator end
function trans=transpose(this) %% Transpose operator
%transpose - overloading of the matlab transpose operator (') function trans=transpose(this)
%transpose - overloading of the matlab transpose operator (')
if (nargout == 0) if (nargout == 0)
mexFaust('transpose',this.objectHandle); mexFaust('transpose',this.objectHandle);
else else
trans = matlab_faust({}); trans = matlab_faust({});
trans.objectHandle = mexFaust('transpose',this.objectHandle); trans.objectHandle = mexFaust('transpose',this.objectHandle);
end end
end end
function trans=ctranspose(this) function trans=ctranspose(this)
if (nargout == 0) if (nargout == 0)
mexFaust('transpose',this.objectHandle); mexFaust('transpose',this.objectHandle);
else else
trans = matlab_faust({}); trans = matlab_faust({});
trans.objectHandle = mexFaust('transpose',this.objectHandle); trans.objectHandle = mexFaust('transpose',this.objectHandle);
end end
end end
%% Size %% Size
function Size=size(this,varargin); function varargout = size(this,varargin)
%size - overload of the matlab size function %size - overload of the matlab size function
Size=mexFaust('size',this.objectHandle); Size=mexFaust('size',this.objectHandle);
if (length(varargin)~=0) nb_input = length(varargin);
if (varargin{1}==1)
Size=Size(1);
elseif (varargin{1}==2) if (nb_input > 1)
Size=Size(2); error('Too many input arguments');
end end
end
if ((nb_input == 1) && (nargout > 1) | (nargout > 2))
end error('Too many output arguments');
end
if (nb_input~=0)
dimension_arg=varargin{1};
if (floor(dimension_arg) ~= dimension_arg)
error('Dimension argument must be a positive integer scalar within indexing range');
end
if (varargin{1}==1)
Size=Size(1);
elseif (varargin{1}==2)
Size=Size(2);
else
Size=1;
end
end
if (nargout < 2)
varargout{1}=Size;
else
varargout{1}=Size(1);
varargout{2}=Size(2);
end
end
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment