Mentions légales du service

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

Add support of complex matrices in matfaust for the 2020 versions of PALM4MSA...

Add support of complex matrices in matfaust for the 2020 versions of PALM4MSA and hierarchical algorithm (CPU & GPU).
parent 72efe2ae
No related branches found
No related tags found
No related merge requests found
......@@ -182,7 +182,11 @@ function varargout = hierarchical(M, p, varargin)
[lambda, core_obj] = mexHierarchical2020Real(M, mex_params);
end
else
error('backend 2020 doesn''t handle yet the complex matrices')
if(gpu)
[lambda, core_obj] = mexHierarchical2020_gpu2Cplx(M, mex_params);
else
[lambda, core_obj] = mexHierarchical2020Cplx(M, mex_params);
end
end
F = Faust(core_obj, isreal(M));
end
......
......@@ -79,17 +79,22 @@ function [F,lambda] = palm4msa(M, p, varargin)
[lambda, core_obj] = mexPalm4MSACplx(mex_params);
end
elseif(backend == 2020)
init_faust = matfaust.Faust(p.init_facts);
% 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);
if(gpu)
[lambda, core_obj] = mexPALM4MSA2020_gpu2Real(mex_params, get_handle(init_faust));
else
[lambda, core_obj] = mexPALM4MSA2020Real(mex_params, get_handle(init_faust));
end
else
error('backend 2020 doesn''t handle yet the complex matrices')
init_faust = complex(matfaust.Faust(p.init_facts));
if(gpu)
[lambda, core_obj] = mexPALM4MSA2020_gpu2Cplx(mex_params, get_handle(init_faust));
else
[lambda, core_obj] = mexPALM4MSA2020Cplx(mex_params, get_handle(complex(init_faust)));
end
end
end
F = Faust(core_obj, isreal(M));
......
......@@ -122,23 +122,24 @@ foreach(SCALAR_AND_FSUFFIX double:Real std::complex<double>:Cplx) # TODO: float
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexPalm4MSA.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexPalm4MSA${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical_fact.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical_fact${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexButterfly.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexButterfly${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020${FSUFFIX}.m @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020${FSUFFIX}.m @ONLY)
if(USE_GPU_MOD)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020_gpu2.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020_gpu2${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020_gpu2.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020_gpu2${FSUFFIX}.m @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020_gpu2.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020_gpu2${FSUFFIX}.m @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020_gpu2.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020_gpu2${FSUFFIX}.cpp @ONLY)
else()
file(REMOVE ${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020_gpu2${FSUFFIX}.cpp) # delete a possible previous file generated with USE_GPU_MOD = ON (because otherwise it fails the building)
file(REMOVE ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020_gpu2${FSUFFIX}.cpp) # delete a possible previous file generated with USE_GPU_MOD = ON (because otherwise it fails the building)
endif()
# Givens FGFT is only for double and float scalars
if(NOT ${FAUST_SCALAR} MATCHES "complex")
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexfgftgivens.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexfgftgivens${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexsvdtj.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexsvdtj${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020${FSUFFIX}.m @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020${FSUFFIX}.m @ONLY)
if(USE_GPU_MOD)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020_gpu2.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020_gpu2${FSUFFIX}.cpp @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020_gpu2.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexPALM4MSA2020_gpu2${FSUFFIX}.m @ONLY)
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020_gpu2.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical2020_gpu2${FSUFFIX}.m @ONLY)
configure_file(${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020_gpu2.cpp.in ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020_gpu2${FSUFFIX}.cpp @ONLY)
else()
file(REMOVE ${FAUST_MATLAB_MEX_SRC_DIR}/mexPALM4MSA2020_gpu2${FSUFFIX}.cpp) # delete a possible previous file generated with USE_GPU_MOD = ON (because otherwise it fails the building)
file(REMOVE ${FAUST_MATLAB_MEX_SRC_DIR}/mexHierarchical2020_gpu2${FSUFFIX}.cpp) # delete a possible previous file generated with USE_GPU_MOD = ON (because otherwise it fails the building)
endif()
endif()
# copy the *.m for factorization now, because we have the FSUFFIX in hands
configure_file(${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical_fact.m.in ${FAUST_MATLAB_DOC_SRC_DIR}/mexHierarchical_fact${FSUFFIX}.m COPYONLY)
......
......@@ -87,8 +87,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
// initialization of the matrix that will be factorized
Faust::MatDense<SCALAR,Cpu> matrix;
mxArray2FaustMat(matlab_matrix,matrix);
Faust::MHTPParams<SCALAR> mhtp_params;
mxArray2FaustMHTPParams<SCALAR>(matlab_params, mhtp_params);
Faust::MHTPParams<Real<SCALAR>> mhtp_params;
mxArray2FaustMHTPParams<Real<SCALAR>>(matlab_params, mhtp_params);
auto *params = mxArray2FaustParams<SCALAR,FPP2>(matlab_params);
FPP2 lambda = params->init_lambda;
......@@ -101,7 +101,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
std::vector<Faust::StoppingCriterion<Real<SCALAR>>> sc = {params->stop_crit_2facts.get_crit(), params->stop_crit_global.get_crit()};
auto th = Faust::hierarchical(matrix, sc, fac_cons, res_cons, lambda, params->isUpdateWayR2L, params->isFactSideLeft, params->factors_format, params->packing_RL, mhtp_params, compute_2norm_on_arrays, params->norm2_threshold, params->norm2_max_iter, params->isVerbose, params->isConstantStepSize, params->step_size);
auto th_times_lambda = th->multiply(lambda);
SCALAR _lambda = SCALAR(lambda);
auto th_times_lambda = th->multiply(_lambda);
delete th;
th = th_times_lambda;
......
......@@ -116,11 +116,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
// initialization of the matrix that will be factorized
Faust::MatDense<SCALAR,Cpu> matrix;
mxArray2FaustMat(matlab_matrix,matrix);
Faust::MatDense<SCALAR,Cpu> gpu_matrix(matrix);
Faust::MatDense<SCALAR,GPU2> gpu_matrix(matrix);
auto *params = mxArray2FaustParams<SCALAR,FPP2>(matlab_params);
Faust::MHTPParams<SCALAR> mhtp_params;
mxArray2FaustMHTPParams<SCALAR>(matlab_params, mhtp_params);
Faust::MHTPParams<Real<SCALAR>> mhtp_params;
mxArray2FaustMHTPParams<Real<SCALAR>>(matlab_params, mhtp_params);
FPP2 lambda = params->init_lambda;
......@@ -135,9 +135,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
// gpu_matrix.Display();
std::vector<Faust::StoppingCriterion<Real<SCALAR>>> sc = {params->stop_crit_2facts.get_crit(), params->stop_crit_global.get_crit()};
// cout << "gpu_fac_cons.size():" << gpu_fac_cons.size() << endl;
auto th = Faust::hierarchical<FPP2, GPU2>(gpu_matrix, sc, gpu_fac_cons, gpu_res_cons, lambda, params->isUpdateWayR2L, params->isFactSideLeft, params->factors_format, params->packing_RL, mhtp_params, compute_2norm_on_arrays, params->norm2_threshold, params->norm2_max_iter, params->isVerbose, params->isConstantStepSize, params->step_size);
auto th = Faust::hierarchical<SCALAR, GPU2>(gpu_matrix, sc, gpu_fac_cons, gpu_res_cons, lambda, params->isUpdateWayR2L, params->isFactSideLeft, params->factors_format, params->packing_RL, mhtp_params, compute_2norm_on_arrays, params->norm2_threshold, params->norm2_max_iter, params->isVerbose, params->isConstantStepSize, params->step_size);
auto th_times_lambda = th->multiply(lambda);
SCALAR _lambda = SCALAR(lambda);
auto th_times_lambda = th->multiply(_lambda);
delete th;
th = th_times_lambda;
......
......@@ -97,11 +97,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
// PALM4MSA parameters
auto params = mxArray2FaustParamsPALM4MSA<SCALAR,FPP2>(prhs[0], presentFields);
Faust::MHTPParams<SCALAR> mhtp_params;
mxArray2FaustMHTPParams<SCALAR>(prhs[0], mhtp_params);
Faust::MHTPParams<Real<SCALAR>> mhtp_params;
mxArray2FaustMHTPParams<Real<SCALAR>>(prhs[0], mhtp_params);
if(params->isVerbose) params->Display();
// Faust::BlasHandle<Cpu> blas_handle;
SCALAR lambda = params->init_lambda;
FPP2 lambda = params->init_lambda;
TransformHelper<SCALAR, Cpu>* F = nullptr, *F_lambda = nullptr;
......@@ -139,7 +139,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
params->norm2_max_iter, params->isConstantStepSize, params->step_size, false /* on_gpu*/, params->isVerbose);
Faust::MatDense<FPP2,Cpu> mat1x1Lambda = Faust::MatDense<FPP2, Cpu>(&lambda, 1, 1);
plhs[0] = FaustMat2mxArray(mat1x1Lambda);
F_lambda = F->multiply(lambda);
SCALAR _lambda = SCALAR(lambda);
F_lambda = F->multiply(_lambda);
delete F; // if init_facts is used F is a copy too
F = F_lambda;
plhs[1] = convertPtr2Mat<Faust::TransformHelper<SCALAR, Cpu>>(F);
......
......@@ -102,11 +102,11 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
// creation of parameters
auto params = mxArray2FaustParamsPALM4MSA<SCALAR,FPP2>(prhs[0], presentFields); //Cpu world
Faust::MHTPParams<SCALAR> mhtp_params;
mxArray2FaustMHTPParams<SCALAR>(prhs[0], mhtp_params);
Faust::MHTPParams<Real<SCALAR>> mhtp_params;
mxArray2FaustMHTPParams<Real<SCALAR>>(prhs[0], mhtp_params);
if(params->isVerbose) params->Display();
SCALAR lambda = params->init_lambda;
FPP2 lambda = params->init_lambda;
TransformHelper<SCALAR, GPU2>* F = nullptr, *F_lambda = nullptr;
......@@ -162,7 +162,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Faust::MatDense<FPP2,Cpu> mat1x1Lambda = Faust::MatDense<FPP2, Cpu>(1, 1, &lambda);
plhs[0] = FaustMat2mxArray(mat1x1Lambda);
F_lambda = F->multiply(lambda);
SCALAR _lambda = SCALAR(lambda);
F_lambda = F->multiply(_lambda);
delete F; // if init_facts is used F is a copy too
F = F_lambda;
auto cpuF = F->tocpu();
......
......@@ -689,7 +689,6 @@ const Params<SCALAR, Cpu, FPP2>* mxArray2FaustParams(const mxArray* matlab_param
{
mxCurrentField = mxGetField(matlab_params, 0, mat_field_type2str(FACTOR_FORMAT).c_str());
factors_format = static_cast<FactorsFormat>((int)mxGetScalar(mxCurrentField));
std::cout << "mx2Faust factors_format:" << factors_format << std::endl;
}
bool packing_RL = Params<SCALAR, Cpu, FPP2>::defaultPackingRL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment