Mentions légales du service

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

wrapper matlab : ajout 2-norm of a faust

parent b09039ad
Branches
Tags
No related merge requests found
......@@ -7,6 +7,7 @@ dim1 = 5;
dim2 = 4;
dim3 = 10;
int_max= 100;
threshold = 10^(-5);
disp('****** TEST MATLAB_FAUST ******* ');
%% creation du faust
......@@ -303,38 +304,38 @@ 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)]);
error(['multiplication faust-vector : invalid result ' ]);
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)]);
error(['multiplication faust-vector with transposition : invalid result ' ]);
end
y_mtimes_trans = mtimes_trans(F,x_trans,istransposed);
if (y_expected_trans ~= y_mtimes_trans)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector with transposition : invalid result ' ]);
end
y_mtimes = mtimes_trans(F,x,nontransposed);
if (y_expected ~= y_mtimes)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector : invalid result ' ]);
end
y_mtimes_trans_N = mtimes_trans(F_trans,x_trans,nontransposed);
if (y_expected_trans ~= y_mtimes_trans_N)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector with transposition : invalid result ' ]);
end
y_mtimes_trans_T = mtimes_trans(F_trans,x,istransposed);
if (y_expected ~= y_mtimes_trans_T)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector : invalid result ' ]);
end
......@@ -366,37 +367,37 @@ 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)]);
error(['multiplication faust-vector : invalid result ' ]);
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)]);
error(['multiplication faust-vector with transposition : invalid result ' ]);
end
Y_mtimes_trans = mtimes_trans(F,X_trans,istransposed);
if (Y_expected_trans ~= Y_mtimes_trans)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector with transposition : invalid result ' ]);
end
Y_mtimes = mtimes_trans(F,X,nontransposed);
if (Y_expected ~= Y_mtimes)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector : invalid result ' ]);
end
Y_mtimes_trans_N = mtimes_trans(F_trans,X_trans,nontransposed);
if (Y_expected_trans ~= Y_mtimes_trans_N)
error(['multiplication faust-vector with transposition : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector with transposition : invalid result ' ]);
end
Y_mtimes_trans_T = mtimes_trans(F_trans,X,istransposed);
if (y_expected ~= y_mtimes_trans_T)
error(['multiplication faust-vector : invalid result within the precision ' num2str(threshold)]);
error(['multiplication faust-vector : invalid result ' ]);
end
......@@ -404,3 +405,19 @@ end
disp('Ok');
disp('TEST 2-norm : ');
real_norm=norm(F_dense);
norm_faust=norm(F);
if (abs(real_norm - norm_faust)>threshold)
error(['norm : invalid result, expected ' num2str(real_norm) ' get norm_faust' num2str(norm_faust)]);
end
disp('Ok');
......@@ -6,9 +6,17 @@ dim1 = 1000;
dim2 = 500;
dim3 = 10;
int_max= 100;
nb_transposition = 100;
nb_multiplication_vector = 100;
nb_access_coeff = 100;
nb_norm = 100;
threshold = 10^(-5);
disp('****** TEST MATLAB_FAUST ******* ');
%% creation du faust
......@@ -196,30 +204,33 @@ disp(['tps mtimes_trans(F,x,nontransposed) : ' num2str(mean(t_mtimes))]);
disp(['tps mtimes_trans(F,x_trans,istransposed) : ' num2str(mean(t_mtimes_trans))]);
disp('Ok');
disp('TEST 2-norm : ');
t_dense_norm=zeros(nb_norm,1);
t_faust_norm=zeros(nb_norm,1);
for i=1:nb_norm
tic
norm_F=norm(F);
t_faust_norm(i) = toc;
tic
norm_F_dense=norm(F);
t_dense_norm = toc;
if (abs(norm_F-norm_F_dense) > threshold)
error(['norm : invalid result, expects ' num2str(norm_F_dense) ' but get ' num2str(norm_F)]);
end
end
disp(['norm dense : ' num2str(mean(t_dense_norm))]);
disp(['norme F : ' num2str(mean(t_faust_norm))]);
disp('Ok');
......@@ -174,6 +174,28 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
return;
}
if (!strcmp("norm",cmd))
{
if (nlhs != 1 || nrhs != 2)
mexErrMsgTxt("norm: Unexpected arguments");
if(core_ptr->size() == 0)
mexErrMsgTxt("get_product : empty faust core");
bool transpose_flag = (bool) mxGetScalar(prhs[2]);
FFPP precision = 0.001;
faust_unsigned_int nbr_iter_max=100;
int flag;
char op;
//spectralNorm(const int nbr_iter_max, FPP threshold, int &flag) const;
double norm_faust = (double) core_ptr->spectralNorm(nbr_iter_max,precision,flag);
plhs[0]=mxCreateDoubleScalar(norm_faust);
return;
}
if (!strcmp("copy",cmd))
{
......
......@@ -255,6 +255,29 @@ classdef Faust
end
end
%% norm : compute the 2-norm of a faust
function norm_faust=norm(this,varargin)
nb_input = length(varargin);
if (nb_input > 1)
error('Too many input arguments');
end
if nb_input == 1
if varargin{1} ~= 2
error('only 2-norm is supported for the faust');
end
end
%% the transpose flag of the faust is ignored because norm(A)==norm(A')
norm_faust=mexFaust('norm',this.matrix.objectHandle);
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment