Mentions légales du service

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

Add wrapper to hierarchical 2020 impl. into matfaust.

parent 6d5b6b29
Branches
Tags
No related merge requests found
......@@ -121,7 +121,7 @@
%> 8
%> <p> @b See @b also matfaust.faust_fact, factparams.ParamsHierarchical, factparams.ParamsHierarchicalSquareMat, factparams.ParamsHierarchicalRectMat
%==========================================================================================
function varargout = hierarchical(M, p)
function varargout = hierarchical(M, p, varargin)
import matfaust.Faust
import matfaust.factparams.*
import matfaust.fact.check_fact_mat
......@@ -158,10 +158,23 @@ function varargout = hierarchical(M, p)
end
% the setters for num_rows/cols verifies consistency with constraints
mex_params = struct('nfacts', p.num_facts, 'cons', {mex_constraints}, 'niter1', p.stop_crits{1}.num_its,'niter2', p.stop_crits{2}.num_its, 'sc_is_criterion_error', p.stop_crits{1}.is_criterion_error, 'sc_error_treshold', p.stop_crits{1}.error_treshold, 'sc_max_num_its', p.stop_crits{1}.max_num_its, 'sc_is_criterion_error2', p.stop_crits{2}.is_criterion_error, 'sc_error_treshold2', p.stop_crits{2}.error_treshold, 'sc_max_num_its2', p.stop_crits{2}.max_num_its, 'nrow', p.data_num_rows, 'ncol', p.data_num_cols, 'fact_side', p.is_fact_side_left, 'update_way', p.is_update_way_R2L, 'verbose', p.is_verbose, 'init_lambda', p.init_lambda);
if(isreal(M))
[lambda, core_obj] = mexHierarchical_factReal(M, mex_params);
else
[lambda, core_obj] = mexHierarchical_factCplx(M, mex_params);
backend = 2016;
nargin = length(varargin);
if(nargin > 0)
backend = varargin{1};
end
if(backend == 2016)
if(isreal(M))
[lambda, core_obj] = mexHierarchical_factReal(M, mex_params);
else
[lambda, core_obj] = mexHierarchical_factCplx(M, mex_params);
end
elseif(backend == 2020)
if(isreal(M))
[lambda, core_obj] = mexHierarchical2020Real(M, mex_params)
else
error('backend 2020 doesn''t handle yet the complex matrices')
end
end
F = Faust(core_obj, isreal(M));
varargout = {F, lambda, p};
......
......@@ -105,6 +105,8 @@ foreach(SCALAR_AND_FSUFFIX double:Real std::complex<double>:Cplx) # TODO: float
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)
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)
......
% TODO
%
/****************************************************************************/
/* Description: */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2020): Nicolas Bellot, Adrien Leman, Thomas Gautrais, */
/* Luc Le Magoarou, Remi Gribonval */
/* INRIA Rennes, FRANCE */
/* http://www.inria.fr/ */
/* */
/* The FAuST Toolbox is distributed under the terms of the GNU Affero */
/* General Public License. */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Affero General Public License as */
/* published by the Free Software Foundation. */
/* */
/* This program is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */
/* See the GNU Affero General Public License for more details. */
/* */
/* You should have received a copy of the GNU Affero General Public */
/* License along with this program. */
/* If not, see <http://www.gnu.org/licenses/>. */
/* */
/* Contacts: */
/* Hakim Hadj-Djilani : hakim.hadj-djilani@inria.fr */
/* Nicolas Bellot : nicolas.bellot@inria.fr */
/* Adrien Leman : adrien.leman@inria.fr */
/* Thomas Gautrais : thomas.gautrais@inria.fr */
/* Luc Le Magoarou : luc.le-magoarou@inria.fr */
/* Remi Gribonval : remi.gribonval@inria.fr */
/* */
/* References: */
/* [1] Le Magoarou L. and Gribonval R., "Flexible multi-layer sparse */
/* approximations of matrices and applications", Journal of Selected */
/* Topics in Signal Processing, 2016. */
/* <https://hal.archives-ouvertes.fr/hal-01167948v1> */
#include "mex.h"
#include "faust_HierarchicalFact.h"
#include "faust_HierarchicalFactFGFT.h"
#include "faust_hierarchical.h"
#include "faust_TransformHelper.h"
#include "class_handle.hpp"
#include <vector>
#include <string>
#include <algorithm>
#include "mx2Faust.h"
#include "faust2Mx.h"
#include <stdexcept>
typedef @FAUST_SCALAR@ SCALAR;
typedef @FACT_FPP@ FPP2;
using namespace std;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
#ifdef FAUST_VERBOSE
if (typeid(SCALAR) == typeid(float))
{
std::cout<<"SCALAR == float"<<std::endl;
}
if (typeid(SCALAR) == typeid(double))
{
std::cout<<"SCALAR == double"<<std::endl;
}
system("sleep 7");
#endif
if(nrhs < 2) // matrix + params + (optional use_csr and packing_RL)
mexErrMsgTxt("The number of arguments of hierarchical2020 must be 2 at least");
const mxArray* matlab_matrix = prhs[0];
const mxArray* matlab_params = prhs[1];
if(!mxIsStruct(matlab_params))
{
mexErrMsgTxt("Input must be a structure.");
}
// initialization of the matrix that will be factorized
Faust::MatDense<SCALAR,Cpu> matrix;
mxArray2FaustMat(matlab_matrix,matrix);
auto *params = mxArray2FaustParams<SCALAR,FPP2>(matlab_params);
FPP2 lambda;
// optional ?
bool use_csr = true, packing_RL = true;
if(nrhs > 2)
use_csr = (bool) mxGetScalar(prhs[2]);
if(nrhs > 3)
packing_RL = (bool) mxGetScalar(prhs[3]);
///////////// HIERARCHICAL LAUNCH ///////////////
try{
// std::cout<<"nb_row : "<<nb_row<<std::endl;
// std::cout<<"nb_col : "<<nb_col<<std::endl;
// params.Display();
//DisplayParams(params);
//creation de hierarchical fact
// Faust::BlasHandle<Cpu> blas_handle;
// Faust::SpBlasHandle<Cpu> spblas_handle;
auto fac_cons = params->cons[0];
auto res_cons = params->cons[1];
cout << "calling hierarchical" << endl;
auto th = Faust::hierarchical(matrix, params->stop_crit_global.get_crit(), fac_cons, res_cons, lambda, params->isUpdateWayR2L, params->isFactSideLeft, use_csr, packing_RL);
Faust::MatDense<FPP2,Cpu> mat1x1Lambda = Faust::MatDense<FPP2, Cpu>(&lambda, 1, 1);
plhs[0] = FaustMat2mxArray(mat1x1Lambda);
plhs[1] = convertPtr2Mat<Faust::TransformHelper<SCALAR, Cpu>>(th);
}
catch (const std::exception& e)
{
// most likely error: compute_lambda : Xhatt_Xhat_tr is too small or Xt_Xhat.trace is too big so lambda is infinite
plhs[1] = nullptr;
mexErrMsgTxt(e.what());
}
delete params;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment