Mentions légales du service

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

Add prox_id for CPU, GPU in default and MatGeneric versions.

parent 33b0445d
No related branches found
No related tags found
No related merge requests found
......@@ -61,7 +61,8 @@ enum faust_constraint_name
CONSTRAINT_NAME_TOEPLITZ,
CONSTRAINT_NAME_CIRC,
CONSTRAINT_NAME_HANKEL,
CONSTRAINT_NAME_SKPERM
CONSTRAINT_NAME_SKPERM,
CONSTRAINT_NAME_ID
};
......
......@@ -309,6 +309,7 @@ bool Faust::ConstraintGeneric::is_constraint_parameter_mat()const
case CONSTRAINT_NAME_TOEPLITZ:
case CONSTRAINT_NAME_HANKEL:
case CONSTRAINT_NAME_CIRC:
case CONSTRAINT_NAME_ID:
return true;
default:
handleError(m_className,"is_constraint_parameter_mat : Unknown type of constraint");
......
......@@ -105,16 +105,12 @@ void Faust::ConstraintMat<FPP,DEVICE>::check_constraint_name()const
switch (this->m_constraintName)
{
case CONSTRAINT_NAME_CONST:
break;
case CONSTRAINT_NAME_SUPP:
break;
case CONSTRAINT_NAME_CIRC:
break;
case CONSTRAINT_NAME_TOEPLITZ:
break;
case CONSTRAINT_NAME_HANKEL:
break;
case CONSTRAINT_NAME_BLKDIAG:
case CONSTRAINT_NAME_ID:
break;
default:
handleError(m_className," cannot create Faust::ConstraintMat objet from an faust_constraint object with this constraint_name");
......@@ -133,6 +129,9 @@ void Faust::ConstraintMat<FPP,DEVICE>::set_default_parameter()
case CONSTRAINT_NAME_SUPP:
m_parameter.setZeros();
break;
case CONSTRAINT_NAME_ID:
// nothing to do
break;
default:
handleError(m_className,"set_default_parameter : cannot create Faust::ConstraintMat objet from an faust_constraint object with this constraint_name");
break;
......@@ -164,6 +163,8 @@ void Faust::ConstraintMat<FPP,DEVICE>::project(Faust::MatDense<FPP,DEVICE> & mat
case CONSTRAINT_NAME_BLKDIAG:
Faust::prox_blockdiag(mat, m_parameter, normalizing);
break;
case CONSTRAINT_NAME_ID:
Faust::prox_id(mat, false); // normalizing is ignored for the CONST prox
default:
handleError(m_className,"project : invalid constraint_name");
break;
......@@ -178,6 +179,8 @@ Faust::MatGeneric<FPP,DEVICE>* Faust::ConstraintMat<FPP,DEVICE>::project_gen(Fau
case CONSTRAINT_NAME_CONST:
//mat=m_parameter;
return Faust::prox_const_gen(mat, m_parameter, false); // normalizing is ignored for the CONST prox
case CONSTRAINT_NAME_ID:
return Faust::prox_id_gen(mat, false); // normalizing is ignored for the ID prox
case CONSTRAINT_NAME_SUPP:
return Faust::prox_supp_gen(mat,m_parameter, normalizing);
case CONSTRAINT_NAME_TOEPLITZ:
......
......@@ -67,7 +67,7 @@ namespace Faust
typedef const Faust::ConstraintInt<FPP,DEVICE> ConstraintTypeSkperm;
typedef const Faust::ConstraintInt<FPP,DEVICE> ConstraintTypeSpPos;
typedef const Faust::ConstraintMat<FPP,DEVICE> ConstraintTypeBlkdiag;
typedef const Faust::ConstraintMat<FPP, DEVICE> ConstraintTypeId;
};
}
......
......@@ -106,6 +106,8 @@ namespace Faust
MatGeneric<FPP,DEV>* prox_supp_gen(MatDense<FPP,DEV> & M, const MatDense<FPP,DEV> & supp, const bool normalized=true, const bool pos=false, const MatType forcedType=None);
template<typename FPP, FDevice DEV>
MatGeneric<FPP,DEV>* prox_const_gen(MatDense<FPP,DEV> & M, const MatDense<FPP,DEV> & supp, const bool normalized=true, const bool pos=false, const MatType forcedType=None);
template<typename FPP, FDevice DEV>
Faust::MatGeneric<FPP,DEV>* prox_id_gen(Faust::MatDense<FPP,DEV> & M, const bool normalized=false, const bool pos=false, const MatType forcedType=None);
}
......
......@@ -169,6 +169,19 @@ Faust::MatGeneric<FPP,DEV>* Faust::prox_const_gen(Faust::MatDense<FPP,DEV> & M,
return new Faust::MatSparse<FPP,DEV>(M);
}
template<typename FPP, FDevice DEV>
Faust::MatGeneric<FPP,DEV>* Faust::prox_id_gen(Faust::MatDense<FPP,DEV> & M, const bool normalized/*=false*/, const bool pos/*=false*/, const MatType forcedType/*=None*/)
{
const faust_unsigned_int dim1 = M.getNbRow();
const faust_unsigned_int dim2 = M.getNbCol();
prox_id(M, normalized, pos);
auto out_is_dense = Faust::sparse_size<FPP>(M.getNonZeros(), dim1) > Faust::dense_size<FPP>(dim1, dim2) && forcedType == None || forcedType == Dense;
if(out_is_dense)
return new Faust::MatDense<FPP,DEV>(M);
else
return new Faust::MatSparse<FPP,DEV>(M);
}
template<typename FPP, FDevice DEV>
Faust::MatGeneric<FPP,DEV>* Faust::prox_sp_gen(Faust::MatDense<FPP, DEV> & M, faust_unsigned_int k, const bool normalized/*=true*/, const bool pos/*=false*/, const MatType forcedType/*=None*/)
{
......@@ -182,7 +195,7 @@ Faust::MatGeneric<FPP,DEV>* Faust::prox_sp_gen(Faust::MatDense<FPP, DEV> & M, fa
return new Faust::MatSparse<FPP,DEV>(M);
}
//TODO: this function si Cpu specialized, it needs to be generalized to any FDevice or explicitly specialized for GPU2
//TODO: this function is Cpu specialized, it needs to be generalized to any FDevice or explicitly specialized for GPU2
//template<typename FPP, FDevice DEV>
//Faust::MatGeneric<FPP,DEV>* Faust::prox_sp_gen(Faust::MatDense<FPP,DEV> & M, faust_unsigned_int k, const bool normalized /* true by deft */, const bool pos, const MatType forcedType/*=None*/)
//{
......
......@@ -103,6 +103,8 @@ namespace Faust
template<typename FPP> faust_unsigned_int sparse_size(faust_unsigned_int nnz, faust_unsigned_int nrows);
template<typename FPP> faust_unsigned_int dense_size(faust_unsigned_int nrows, faust_unsigned_int ncols);
template<typename FPP>
void prox_id(MatDense<FPP,Cpu> & M, const bool normalized=false, const bool pos=false);
}
......
......@@ -688,4 +688,11 @@ void Faust::prox_skperm(Faust::MatDense<FPP, Cpu> & M_, const unsigned int k, co
M = (matching.array() > 0).select(M, 0);
if(normalized) M_.normalize();
}
template<typename FPP>
void Faust::prox_id(Faust::MatDense<FPP,Cpu> & M, const bool normalized /* deft to false */, const bool pos /* false */)
{
if(pos) pre_prox_pos(M);
if(normalized) M.normalize();
}
#endif
......@@ -64,7 +64,9 @@ namespace Faust
template<typename FPP>
void prox_supp(MatDense<FPP,GPU2> & M, const MatDense<FPP,GPU2> & supp, const bool normalized=true, const bool pos=false);
template<typename FPP>
void prox_const(MatDense<FPP,GPU2> & M, const MatDense<FPP,GPU2> & supp, const bool normalized=true, const bool pos=false);
void prox_const(MatDense<FPP,GPU2> & M, const MatDense<FPP,GPU2> & supp, const bool normalized=false, const bool pos=false);
template<typename FPP>
void prox_id(MatDense<FPP,GPU2> & M, const bool normalized=false, const bool pos=false);
template<typename FPP, typename FPP2>
void prox_normcol(MatDense<FPP,GPU2> & M,FPP2 s, const bool normalized=false, const bool pos=false);
......
......@@ -117,7 +117,7 @@ namespace Faust
}
template<typename FPP>
void prox_const(MatDense<FPP,GPU2> & M, const MatDense<FPP,GPU2> & supp, const bool normalized/*=true*/, const bool pos/*=false*/)
void prox_const(MatDense<FPP,GPU2> & M, const MatDense<FPP,GPU2> & supp, const bool normalized/*=false*/, const bool pos/*=false*/)
{
MatDense<FPP,Cpu> cpuM = M.tocpu();
MatDense<FPP,Cpu> cpu_supp = supp.tocpu();
......@@ -125,6 +125,14 @@ namespace Faust
M = cpuM;
}
template<typename FPP>
void prox_id(MatDense<FPP,GPU2> & M, const bool normalized/*=false*/, const bool pos/*=false*/)
{
MatDense<FPP,Cpu> cpuM = M.tocpu();
prox_id(cpuM, normalized, pos);
M = cpuM;
}
template<typename FPP, typename FPP2>
void prox_normcol(MatDense<FPP,GPU2> & M,FPP2 s, const bool normalized/*=false*/, const bool pos/*=false*/)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment