Mentions légales du service

Skip to content
Snippets Groups Projects
Commit caa35c87 authored by hhakim's avatar hhakim
Browse files

Add err_period argument to matfaust eigtj.

parent e09837bb
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
%> @param nGivens, integer [optional if tol is set] targeted number of Givens rotations. %> @param nGivens, integer [optional if tol is set] targeted number of Givens rotations.
%> The number of rotations per factor of V is defined by nGivens_per_fac. %> The number of rotations per factor of V is defined by nGivens_per_fac.
%> @param 'tol', number [optional if nGivens is set] the tolerance error at which the algorithm stops. The default value is zero so that stopping is based on reaching the targeted nGivens. %> @param 'tol', number [optional if nGivens is set] the tolerance error at which the algorithm stops. The default value is zero so that stopping is based on reaching the targeted nGivens.
%> @param 'err_period', int: it defines the period, in number of factors of V,
%> the error is compared to tol (reducing the period spares some factors but increases slightly the computational cost because the error
%> is computed more often).
%> @param 'order', char [optional, default is ‘ascend’] order of eigenvalues, possible choices are ‘ascend, 'descend' or 'undef' (to avoid a sorting operation and save some time). %> @param 'order', char [optional, default is ‘ascend’] order of eigenvalues, possible choices are ‘ascend, 'descend' or 'undef' (to avoid a sorting operation and save some time).
%> @param 'nGivens_per_fac', integer [optional, default is <code>floor(size(M, 1)/2)</code>] targeted number of Givens rotations per factor of V. Must be an integer between 1 to <code>floor(size(M, 1)/2)</code>. %> @param 'nGivens_per_fac', integer [optional, default is <code>floor(size(M, 1)/2)</code>] targeted number of Givens rotations per factor of V. Must be an integer between 1 to <code>floor(size(M, 1)/2)</code>.
%> @param 'relerr', bool [optional, default is true] the type of error used as stopping criterion. (true) for the relative error norm(V*D*V'-M, 'fro')/norm(M, 'fro'), (false) for the absolute error norm(V*D*V'-M, 'fro'). %> @param 'relerr', bool [optional, default is true] the type of error used as stopping criterion. (true) for the relative error norm(V*D*V'-M, 'fro')/norm(M, 'fro'), (false) for the absolute error norm(V*D*V'-M, 'fro').
...@@ -92,8 +95,9 @@ function [V,D] = eigtj(M, varargin) ...@@ -92,8 +95,9 @@ function [V,D] = eigtj(M, varargin)
enable_large_Faust = false; enable_large_Faust = false;
argc = length(varargin); argc = length(varargin);
order = 1; % ascending order order = 1; % ascending order
err_period = 100;
if(argc > 0) if(argc > 0)
for i=1:argc for i=1:2:argc
switch(varargin{i}) switch(varargin{i})
case 'enable_large_Faust' case 'enable_large_Faust'
if(argc == i || ~ islogical(varargin{i+1})) if(argc == i || ~ islogical(varargin{i+1}))
...@@ -144,6 +148,12 @@ function [V,D] = eigtj(M, varargin) ...@@ -144,6 +148,12 @@ function [V,D] = eigtj(M, varargin)
order = 0; order = 0;
end end
end end
case 'err_period'
if(argc == i || ~ isscalar(varargin{i+1}))
error('err_period keyword argument is not followed by a number')
else
err_period = floor(real(varargin{i+1}));
end
otherwise otherwise
if(isstr(varargin{i}) && (~ strcmp(varargin{i}, 'ascend') && ~ strcmp(varargin{i}, 'descend') && ~ strcmp(varargin{i}, 'undef')) ) if(isstr(varargin{i}) && (~ strcmp(varargin{i}, 'ascend') && ~ strcmp(varargin{i}, 'descend') && ~ strcmp(varargin{i}, 'undef')) )
error([ varargin{i} ' unrecognized argument']) error([ varargin{i} ' unrecognized argument'])
...@@ -158,11 +168,11 @@ function [V,D] = eigtj(M, varargin) ...@@ -158,11 +168,11 @@ function [V,D] = eigtj(M, varargin)
nGivens_per_fac = min(nGivens_per_fac, nGivens); nGivens_per_fac = min(nGivens_per_fac, nGivens);
end end
if(strcmp(class(M), 'single')) if(strcmp(class(M), 'single'))
[core_obj, D] = mexfgftgivensRealFloat(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust); [core_obj, D] = mexfgftgivensRealFloat(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust, err_period);
D = sparse(diag(real(double(D)))); D = sparse(diag(real(double(D))));
V = Faust(core_obj, isreal(M), 'cpu', 'float'); V = Faust(core_obj, isreal(M), 'cpu', 'float');
else else
[core_obj, D] = mexfgftgivensReal(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust); [core_obj, D] = mexfgftgivensReal(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust, err_period);
D = sparse(diag(real(D))); D = sparse(diag(real(D)));
V = Faust(core_obj, isreal(M)); V = Faust(core_obj, isreal(M));
end end
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
%> is computed more often). %> is computed more often).
%> %>
%> @retval [U,S,V]: such that U*S*V' is the approximate of M with: %> @retval [U,S,V]: such that U*S*V' is the approximate of M with:
%> - S: (sparse real diagonal matrix) the singular values in descendant order. %> - S: (sparse real diagonal matrix) the singular values in descending order.
%> - U, V: (Faust objects) orthonormal transforms. %> - U, V: (Faust objects) orthonormal transforms.
%> %>
%> @b Example %> @b Example
......
...@@ -55,9 +55,9 @@ typedef @FACT_FPP@ FPP2; ...@@ -55,9 +55,9 @@ typedef @FACT_FPP@ FPP2;
using namespace Faust; using namespace Faust;
void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, mxArray **plhs); void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, const int err_period, mxArray **plhs);
void fgft_givens_cplx(const mxArray* matlab_matrix, int J, int t, double tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, mxArray **plhs); void fgft_givens_cplx(const mxArray* matlab_matrix, int J, int t, double tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, const int err_period, mxArray **plhs);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{ {
...@@ -69,8 +69,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -69,8 +69,9 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
bool rel_err = true; bool rel_err = true;
bool enable_large_Faust = false; bool enable_large_Faust = false;
int order; int order;
int err_period = 100;
if(nrhs < 2 || nrhs > 8) if(nrhs < 2 || nrhs > 9)
mexErrMsgTxt("Bad number of input arguments"); mexErrMsgTxt("Bad number of input arguments");
J = (int) mxGetScalar(prhs[1]); J = (int) mxGetScalar(prhs[1]);
...@@ -86,19 +87,21 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) ...@@ -86,19 +87,21 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
order = (int) mxGetScalar(prhs[6]); //eigenvalues order order = (int) mxGetScalar(prhs[6]); //eigenvalues order
if(nrhs >= 8) if(nrhs >= 8)
enable_large_Faust = (bool) mxGetScalar(prhs[7]); enable_large_Faust = (bool) mxGetScalar(prhs[7]);
if(nrhs >= 9)
err_period = (int) mxGetScalar(prhs[8]);
tol *= tol; // C++ backend works with squared norm error tol *= tol; // C++ backend works with squared norm error
const mxArray* matlab_matrix = prhs[0]; // Laplacian const mxArray* matlab_matrix = prhs[0]; // Laplacian
if(mxIsComplex(matlab_matrix)) if(mxIsComplex(matlab_matrix))
fgft_givens_cplx(matlab_matrix, J, t, tol, verbosity, rel_err, order, enable_large_Faust, plhs); fgft_givens_cplx(matlab_matrix, J, t, tol, verbosity, rel_err, order, enable_large_Faust, err_period, plhs);
else else
fgft_givens(matlab_matrix, J, t, tol, verbosity, rel_err, order, enable_large_Faust, plhs); fgft_givens(matlab_matrix, J, t, tol, verbosity, rel_err, order, enable_large_Faust, err_period, plhs);
} }
void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, mxArray **plhs) void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, const int err_period, mxArray **plhs)
{ {
// initialization of the matrix that will be factorized // initialization of the matrix that will be factorized
Faust::MatGeneric<SCALAR,Cpu>* Lap; Faust::MatGeneric<SCALAR,Cpu>* Lap;
...@@ -113,18 +116,18 @@ void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, u ...@@ -113,18 +116,18 @@ void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, u
mxArray2FaustspMat(matlab_matrix,sLap); mxArray2FaustspMat(matlab_matrix,sLap);
Lap = &sLap; Lap = &sLap;
if(t <= 1) if(t <= 1)
algo = new GivensFGFT<SCALAR,Cpu,FPP2>(sLap, J, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFT<SCALAR,Cpu,FPP2>(sLap, J, verbosity, tol, rel_err, enable_large_Faust, err_period);
else else
algo = new GivensFGFTParallel<SCALAR,Cpu,FPP2>(sLap, J, t, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFTParallel<SCALAR,Cpu,FPP2>(sLap, J, t, verbosity, tol, rel_err, enable_large_Faust, err_period);
}else }else
{ {
mxArray2FaustMat(matlab_matrix,dLap); mxArray2FaustMat(matlab_matrix,dLap);
Lap = &dLap; Lap = &dLap;
if(t <= 1) if(t <= 1)
algo = new GivensFGFT<SCALAR,Cpu,FPP2>(dLap, J, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFT<SCALAR,Cpu,FPP2>(dLap, J, verbosity, tol, rel_err, enable_large_Faust, err_period);
else else
algo = new GivensFGFTParallel<SCALAR,Cpu,FPP2>(dLap, J, t, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFTParallel<SCALAR,Cpu,FPP2>(dLap, J, t, verbosity, tol, rel_err, enable_large_Faust, err_period);
} }
...@@ -153,7 +156,7 @@ void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, u ...@@ -153,7 +156,7 @@ void fgft_givens(const mxArray* matlab_matrix, int J, int t, Real<SCALAR> tol, u
} }
void fgft_givens_cplx(const mxArray* matlab_matrix, int J, int t, double tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, mxArray **plhs) void fgft_givens_cplx(const mxArray* matlab_matrix, int J, int t, double tol, unsigned int verbosity, bool rel_err, int order, const bool enable_large_Faust, const int err_period, mxArray **plhs)
{ {
// initialization of the matrix that will be factorized // initialization of the matrix that will be factorized
Faust::MatGeneric<complex<SCALAR>,Cpu>* Lap; Faust::MatGeneric<complex<SCALAR>,Cpu>* Lap;
...@@ -168,18 +171,18 @@ void fgft_givens_cplx(const mxArray* matlab_matrix, int J, int t, double tol, un ...@@ -168,18 +171,18 @@ void fgft_givens_cplx(const mxArray* matlab_matrix, int J, int t, double tol, un
mxArray2FaustspMat(matlab_matrix,sLap); mxArray2FaustspMat(matlab_matrix,sLap);
Lap = &sLap; Lap = &sLap;
if(t <= 1) if(t <= 1)
algo = new GivensFGFTComplex<complex<SCALAR>,Cpu,FPP2>(sLap, J, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFTComplex<complex<SCALAR>,Cpu,FPP2>(sLap, J, verbosity, tol, rel_err, enable_large_Faust, err_period);
else else
algo = new GivensFGFTParallelComplex<complex<SCALAR>,Cpu,FPP2>(sLap, J, t, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFTParallelComplex<complex<SCALAR>,Cpu,FPP2>(sLap, J, t, verbosity, tol, rel_err, enable_large_Faust, err_period);
}else }else
{ {
mxArray2FaustMat(matlab_matrix,dLap); mxArray2FaustMat(matlab_matrix,dLap);
Lap = &dLap; Lap = &dLap;
if(t <= 1) if(t <= 1)
algo = new GivensFGFTComplex<complex<SCALAR>,Cpu,FPP2>(dLap, J, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFTComplex<complex<SCALAR>,Cpu,FPP2>(dLap, J, verbosity, tol, rel_err, enable_large_Faust, err_period);
else else
algo = new GivensFGFTParallelComplex<complex<SCALAR>,Cpu,FPP2>(dLap, J, t, verbosity, tol, rel_err, enable_large_Faust); algo = new GivensFGFTParallelComplex<complex<SCALAR>,Cpu,FPP2>(dLap, J, t, verbosity, tol, rel_err, enable_large_Faust, err_period);
} }
algo->compute_facts(); algo->compute_facts();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment