Mentions légales du service

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

Add C++ missing non-normalized proxs for discrete sparsity and bind them into...

Add C++ missing non-normalized proxs for discrete sparsity and bind them into pyfaust(.factparams.ContraintInt).
parent 90bfc17f
Branches
Tags
No related merge requests found
/****************************************************************************/
/* Description: */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2019): Hakim Hadj-Djilani, 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: */
/****************************************************************************/
/* Description: */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2019): Hakim Hadj-Djilani, 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 H. 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> */
/****************************************************************************/
#ifndef FAUST_PROX_H
#define FAUST_PROX_H
#include "faust_MatDense.h"
#include "faust_constant.h"
#include "faust_exception.h"
#include "faust_Vect.h"
/** \brief faust_prox.h contains the projection operator: <br>
* PALM relies on projections onto the constraint sets for each factor at each iteration, <br>
* so the projection operator should be simple and easy to compute.
*/
namespace Faust {
template<typename FPP>
bool partial_sort_comp (const std::pair<int, FPP>& pair1, const std::pair<int, FPP>& pair2);
template<typename FPP>
void sort_idx(const std::vector<FPP> &v, std::vector<int>& idx, int s);
template<typename FPP>
void prox_sp(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_sp_pos(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_spcol(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_splin(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_spcol_normfree(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_splin_normfree(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_splincol(Faust::MatDense<FPP,Cpu> &M,faust_unsigned_int k);
template<typename FPP, typename FPP2>
void prox_normcol(Faust::MatDense<FPP,Cpu> & M,FPP2 s);
template<typename FPP, typename FPP2>
void prox_normlin(Faust::MatDense<FPP,Cpu> & M,FPP2 s);
template<typename FPP>
void prox_supp(Faust::MatDense<FPP,Cpu> & M, const Faust::MatDense<FPP,Cpu> & supp);
// template<typename FPP>
// void prox_blkdiag(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
}
#include "faust_prox.hpp"
#endif
/* 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> */
/****************************************************************************/
#ifndef FAUST_PROX_H
#define FAUST_PROX_H
#include "faust_MatDense.h"
#include "faust_constant.h"
#include "faust_exception.h"
#include "faust_Vect.h"
/** \brief faust_prox.h contains the projection operator: <br>
* PALM relies on projections onto the constraint sets for each factor at each iteration, <br>
* so the projection operator should be simple and easy to compute.
*/
namespace Faust {
template<typename FPP>
bool partial_sort_comp (const std::pair<int, FPP>& pair1, const std::pair<int, FPP>& pair2);
template<typename FPP>
void sort_idx(const std::vector<FPP> &v, std::vector<int>& idx, int s);
template<typename FPP>
void prox_sp(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_sp_normfree(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_sp_pos(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_sp_pos_normfree(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_spcol(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_splin(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_spcol_normfree(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_splin_normfree(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
template<typename FPP>
void prox_splincol(Faust::MatDense<FPP,Cpu> &M,faust_unsigned_int k);
template<typename FPP>
void prox_splincol_normfree(Faust::MatDense<FPP,Cpu> &M,faust_unsigned_int k);
template<typename FPP, typename FPP2>
void prox_normcol(Faust::MatDense<FPP,Cpu> & M,FPP2 s);
template<typename FPP, typename FPP2>
void prox_normlin(Faust::MatDense<FPP,Cpu> & M,FPP2 s);
template<typename FPP>
void prox_supp(Faust::MatDense<FPP,Cpu> & M, const Faust::MatDense<FPP,Cpu> & supp);
template<typename FPP>
void prox_supp_normfree(Faust::MatDense<FPP,Cpu> & M, const Faust::MatDense<FPP,Cpu> & supp);
// template<typename FPP>
// void prox_blkdiag(Faust::MatDense<FPP,Cpu> & M,faust_unsigned_int k);
}
#include "faust_prox.hpp"
#endif
This diff is collapsed.
......@@ -160,13 +160,14 @@ class ConstraintInt(ConstraintGeneric):
'ConstraintName with a int type name '
'(name.is_int_constraint() must return True).')
def project(self, M):
def project(self, M, normalized=True):
"""
<b/> See: ConstraintGeneric.project
"""
super(ConstraintInt, self).project(M)
return _FaustCorePy.ConstraintIntCore.project(M, self._name.name, self._num_rows,
self._num_cols, self._cons_value)
self._num_cols, self._cons_value,
normalized)
class ConstraintMat(ConstraintGeneric):
......
......@@ -120,7 +120,7 @@ cdef extern from "FaustFact.h":
unsigned long parameter
void prox_int[FPP](unsigned int cons_type, unsigned long cons_param, FPP* mat_in, unsigned long num_rows,
unsigned long num_cols, FPP* mat_out)
unsigned long num_cols, FPP* mat_out, const bool normalized)
void prox_real[FPP,FPP2](unsigned int cons_type, FPP2 cons_param, FPP* mat_in, unsigned long num_rows,
unsigned long num_cols, FPP* mat_out)
......
......@@ -37,7 +37,7 @@ class PyxConstraintMat : public PyxConstraintGeneric
template<typename FPP>
void prox_int(unsigned int cons_type, unsigned long cons_param, FPP* mat_in, unsigned long num_rows,
unsigned long num_cols, FPP* mat_out);
unsigned long num_cols, FPP* mat_out, const bool normalized=true);
template<typename FPP, typename FPP2>
void prox_real(unsigned int cons_type, FPP2 cons_param, FPP* mat_in, unsigned long num_rows,
......
......@@ -78,25 +78,41 @@ void prox_mat(unsigned int cons_type, FPP* cons_param, FPP* mat_in, unsigned lon
template<typename FPP>
void prox_int(unsigned int cons_type, unsigned long cons_param, FPP* mat_in, unsigned long num_rows,
unsigned long num_cols, FPP* mat_out)
unsigned long num_cols, FPP* mat_out, const bool normalized /* default to true */)
{
Faust::MatDense<FPP, Cpu> fmat(mat_in, num_rows, num_cols);
switch(static_cast<faust_constraint_name>(cons_type))
{
case CONSTRAINT_NAME_SPCOL: /*!< fixed number of non zero elements per column INT (frobenius norm 1) */
Faust::prox_spcol(fmat, (faust_unsigned_int) cons_param);
if(normalized)
Faust::prox_spcol(fmat, (faust_unsigned_int) cons_param);
else
Faust::prox_spcol_normfree(fmat, (faust_unsigned_int) cons_param);
break;
case CONSTRAINT_NAME_SPLIN: /*!< fixed number of non zero elements per line INT (frobenius norm 1) */
Faust::prox_splin(fmat, (faust_unsigned_int) cons_param);
if(normalized)
Faust::prox_splin(fmat, (faust_unsigned_int) cons_param);
else
Faust::prox_splin_normfree(fmat, (faust_unsigned_int) cons_param);
break;
case CONSTRAINT_NAME_SPLINCOL:
Faust::prox_splincol(fmat, (faust_unsigned_int) cons_param);
if(normalized)
Faust::prox_splincol(fmat, (faust_unsigned_int) cons_param);
else
Faust::prox_splincol_normfree(fmat, (faust_unsigned_int) cons_param);
break;
case CONSTRAINT_NAME_SP_POS:/**< fixed number of non zeros coefficients: INT (frobenius norm 1) */
Faust::prox_sp_pos(fmat, (faust_unsigned_int) cons_param);
if(normalized)
Faust::prox_sp_pos(fmat, (faust_unsigned_int) cons_param);
else
Faust::prox_sp_pos_normfree(fmat, (faust_unsigned_int) cons_param);
break;
case CONSTRAINT_NAME_SP:
Faust::prox_sp(fmat, (faust_unsigned_int) cons_param); break;
if(normalized)
Faust::prox_sp(fmat, (faust_unsigned_int) cons_param);
else
Faust::prox_sp_normfree(fmat, (faust_unsigned_int) cons_param);
break;
default:
throw invalid_argument("PyxConstraintInt::project() inconsistent constraint name");
}
......
......@@ -807,7 +807,7 @@ cdef class ConstraintIntCore:
# so it can't create the object before the call
# in that conditions a static method will suffice
@staticmethod
def project(M, name, num_rows, num_cols, parameter):
def project(M, name, num_rows, num_cols, parameter, normalized=True):
cdef double[:,:] M_view_dbl
cdef double[:,:] M_out_view_dbl
cdef complex[:,:] M_view_cplx
......@@ -824,12 +824,14 @@ cdef class ConstraintIntCore:
M_view_dbl = M
M_out_view_dbl = M_out
FaustCoreCy.prox_int[double](name, parameter, &M_view_dbl[0,0], num_rows,
num_cols,&M_out_view_dbl[0,0])
num_cols,&M_out_view_dbl[0,0],
normalized)
else:
M_view_cplx = M
M_out_view_cplx = M_out
FaustCoreCy.prox_int[complex](name, parameter, &M_view_cplx[0,0],
num_rows, num_cols, &M_out_view_cplx[0,0])
num_rows, num_cols,
&M_out_view_cplx[0,0], normalized)
return M_out
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment