Mentions légales du service

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

Support float scalar type for matfaust.fact.palm4msa (2016 and 2020 backends),...

Support float scalar type for matfaust.fact.palm4msa (2016 and 2020 backends), eigtj, svdtj and butterfly.
parent d634ebf9
No related branches found
No related tags found
No related merge requests found
......@@ -28,10 +28,15 @@ function F = butterfly(M, varargin)
elseif(strcmp(dir, 'left'))
dir = 0;
end
if(isreal(M))
core_obj = mexButterflyReal(M, dir);
else
core_obj = mexButterflyCplx(M, dir);
end
F = Faust(core_obj, isreal(M));
if(strcmp(class(M), 'single'))
core_obj = mexButterflyRealFloat(M, dir);
F = Faust(core_obj, isreal(M), 'cpu', 'float');
else
if(isreal(M))
core_obj = mexButterflyReal(M, dir);
else
core_obj = mexButterflyCplx(M, dir);
end
F = Faust(core_obj, isreal(M));
end
end
......@@ -18,7 +18,7 @@
%>&nbsp;&nbsp;&nbsp; <b>[V,D]= eigtj(M,’nGivens’,n,’order’,’descend’) </b> same as above where the diagonal entries of D are the approximate eigenvalues in descending order (and with columns of V permuted accordingly).<br/>
%>&nbsp;&nbsp;&nbsp; <b>eigtj(M, 'nGivens', n, 'nGivens_per_fac', t, 'tol', 0.01, 'relerr', true)</b> uses a stopping criterion based on absolute error norm(V*D*V'-M, 'fro'). This criterion is concurrent to nGivens (here n).<br/>
%>
%> @param M the matrix to diagonalize. Must be real and symmetric, or complex hermitian. Can be in dense or sparse format.
%> @param M the matrix to diagonalize. Must be real and symmetric, or complex hermitian. Can be in dense or sparse format. The class(M) value can be double or single (only if isreal(M) is true).
%> @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.
%> @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.
......@@ -157,7 +157,13 @@ function [V,D] = eigtj(M, varargin)
if(nGivens > 0)
nGivens_per_fac = min(nGivens_per_fac, nGivens);
end
[core_obj, D] = mexfgftgivensReal(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust);
D = sparse(diag(real(D)));
V = Faust(core_obj, isreal(M));
if(strcmp(class(M), 'single'))
[core_obj, D] = mexfgftgivensRealFloat(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust);
D = sparse(diag(real(double(D))));
V = Faust(core_obj, isreal(M), 'cpu', 'float');
else
[core_obj, D] = mexfgftgivensReal(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust);
D = sparse(diag(real(D)));
V = Faust(core_obj, isreal(M));
end
end
......@@ -2,7 +2,7 @@
%> @brief Factorizes the matrix M with Palm4MSA algorithm using the parameters set in p.
%>
%>
%> @param M the dense matrix to factorize.
%> @param M the dense matrix to factorize. The class(M) value can be double or single (only if isreal(M) is true). This class has a major impact on performance.
%> @param p the matfaust.factparams.ParamsPalm4MSA instance to define the algorithm parameters.
%> @param 'backend',int (optional) the backend to use (the C++ implementation). Must be 2016 (the default) or 2020 (which should be faster for most of the factorizations).
%> @param 'gpu', bool (optional) set to true to execute the algorithm using the GPU implementation. This option is only available when backend==2020.
......@@ -47,6 +47,12 @@ function [F,lambda] = palm4msa(M, p, varargin)
backend = 2016;
nargin = length(varargin);
gpu = false;
is_float = strcmp(class(M), 'single');
if(is_float)
dtype = 'float';
else
dtype = 'double'; % also for complex double
end
if(nargin > 0)
for i=1:nargin
switch(varargin{i})
......@@ -74,7 +80,11 @@ function [F,lambda] = palm4msa(M, p, varargin)
end
if(backend == 2016)
if(isreal(M))
[lambda, core_obj] = mexPalm4MSAReal(mex_params);
if(is_float)
[lambda, core_obj] = mexPalm4MSARealFloat(mex_params);
else
[lambda, core_obj] = mexPalm4MSAReal(mex_params);
end
else
[lambda, core_obj] = mexPalm4MSACplx(mex_params);
end
......@@ -82,11 +92,19 @@ function [F,lambda] = palm4msa(M, p, varargin)
% no need to keep the ParamsPalm4MSA extracted/generated cell for init_facts
% mex_params = rmfield(mex_params, 'init_facts')
if(isreal(M))
init_faust = matfaust.Faust(p.init_facts);
init_faust = matfaust.Faust(p.init_facts, 'dtype', dtype);
if(gpu)
[lambda, core_obj] = mexPALM4MSA2020_gpu2Real(mex_params, get_handle(init_faust));
if(is_float)
[lambda, core_obj] = mexPALM4MSA2020_gpu2RealFloat(mex_params, get_handle(init_faust));
else
[lambda, core_obj] = mexPALM4MSA2020_gpu2Real(mex_params, get_handle(init_faust));
end
else
[lambda, core_obj] = mexPALM4MSA2020Real(mex_params, get_handle(init_faust));
if(is_float)
[lambda, core_obj] = mexPALM4MSA2020RealFloat(mex_params, get_handle(init_faust));
else
[lambda, core_obj] = mexPALM4MSA2020Real(mex_params, get_handle(init_faust));
end
end
else
init_faust = complex(matfaust.Faust(p.init_facts));
......@@ -97,5 +115,5 @@ function [F,lambda] = palm4msa(M, p, varargin)
end
end
end
F = Faust(core_obj, isreal(M));
F = Faust(core_obj, isreal(M), 'cpu', dtype);
end
......@@ -14,7 +14,7 @@
%> &nbsp;&nbsp;&nbsp; @b <b>[U,S,V] = svdtj(M,’nGivens’,n,’tol’,0.01,’nGivens_per_fac’,t) </b>same as above with (up to) t Givens rotations per factor<br/>
%>
%>
%> @param M: a real or complex, dense or sparse matrix.
%> @param M: a real or complex, dense or sparse matrix. The class(M) value can be double or single (only if isreal(M) is true).
%> @param nGivens, integer: see fact.eigtj
%> @param 'tol', number see fact.eigtj (NB: as described below, the error tolerance is not exactly for the approximate SVD but for the subsequent eigtj calls).
%> @param 'relerr', bool see fact.eigtj
......@@ -154,8 +154,15 @@ function [U,S,V] = svdtj(M, varargin)
if(nGivens > 0)
nGivens_per_fac = min(nGivens_per_fac, nGivens);
end
[core_obj1, S, core_obj2] = mexsvdtjReal(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust);
S = sparse(diag(real(S)));
U = Faust(core_obj1, isreal(M));
V = Faust(core_obj2, isreal(M));
if(strcmp(class(M), 'single'))
[core_obj1, S, core_obj2] = mexsvdtjRealFloat(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust);
S = sparse(diag(real(double(S))));
U = Faust(core_obj1, isreal(M), 'cpu', 'float');
V = Faust(core_obj2, isreal(M), 'cpu', 'float');
else
[core_obj1, S, core_obj2] = mexsvdtjReal(M, nGivens, nGivens_per_fac, verbosity, tol, relerr, order, enable_large_Faust);
S = sparse(diag(real(S)));
U = Faust(core_obj1, isreal(M));
V = Faust(core_obj2, isreal(M));
end
end
......@@ -55,7 +55,7 @@ typedef @FACT_FPP@ FPP2;
using namespace Faust;
void fgft_givens(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(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_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);
......@@ -98,7 +98,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
}
void fgft_givens(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(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)
{
// initialization of the matrix that will be factorized
Faust::MatGeneric<SCALAR,Cpu>* Lap;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment