Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 136e98a0 authored by hhakim's avatar hhakim
Browse files

Refactor palm4msa2020 by using MatDense::adjoint() and new function fill_of_eyes().

parent f7b45660
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,21 @@ namespace Faust
const unsigned int norm2_max_iter=FAUST_NORM2_MAX_ITER,
const bool constant_step_size=false, const Real<FPP> step_size=FAUST_PRECISION);
/**
* \brief Fill S with nfacts eye() matrices.
*
* S must be an empty Faust. If S is already composed of factors an exception is raised.
*
* \param sparse if true eyes are MatSparse, they are MatDense otherwise.
*
*/
template <typename FPP, FDevice DEVICE>
void fill_of_eyes(Faust::TransformHelper<FPP,DEVICE>& S,
const unsigned int nfacts,
const bool sparse,
const std::vector<std::pair<faust_unsigned_int,faust_unsigned_int>> dims);
//TODO: maybe move this function in a Faust::utils module (for now it serves only for PALM4MSA)
}
#include "faust_palm4msa2020.hpp"
#endif
......@@ -25,32 +25,33 @@ void Faust::palm4msa(const Faust::MatDense<FPP,DEVICE>& A,
for(auto c: constraints)
dims.push_back(make_pair(c->get_rows(), c->get_cols()));
Faust::MatDense<FPP,DEVICE> A_H = A;
A_H.conjugate(false);
A_H.transpose();
A_H.adjoint();
// if(S.size() != nfacts)
// {
//// S = Faust::TransformHelper<FPP,DEVICE>();
// //TODO: refactor the id factor gen. into TransformHelper
// for(auto fdims : dims)
// {
// // init all facts as identity matrices
// // with proper dimensions
// Faust::MatGeneric<FPP,DEVICE>* fact;
// if(use_csr)
// {
// auto sfact = new Faust::MatSparse<FPP,DEVICE>(fdims.first, fdims.second);
// sfact->setEyes();
// fact = sfact;
// }
// else
// {
// auto dfact = new Faust::MatDense<FPP,DEVICE>(fdims.first, fdims.second);
// dfact->setEyes();
// fact = dfact;
// }
// S.push_back(fact); //TODO: copying=false
// }
// }
if(S.size() != nfacts)
{
// S = Faust::TransformHelper<FPP,DEVICE>();
//TODO: refactor the id factor gen. into TransformHelper
for(auto fdims : dims)
{
// init all facts as identity matrices
// with proper dimensions
Faust::MatGeneric<FPP,DEVICE>* fact;
if(use_csr)
{
auto sfact = new Faust::MatSparse<FPP,DEVICE>(fdims.first, fdims.second);
sfact->setEyes();
fact = sfact;
}
else
{
auto dfact = new Faust::MatDense<FPP,DEVICE>(fdims.first, fdims.second);
dfact->setEyes();
fact = dfact;
}
S.push_back(fact); //TODO: copying=false
}
}
fill_of_eyes(S, nfacts, use_csr, dims);
int i = 0, f_id;
std::function<void()> init_fid, next_fid;
std::function<bool()> updating_facs;
......@@ -107,11 +108,9 @@ void Faust::palm4msa(const Faust::MatDense<FPP,DEVICE>& A,
if(sc.isCriterionErr())
error = tmp.norm();
//TODO: do something to lighten the double transpose conjugate
tmp.conjugate(false);
tmp.transpose();
tmp.adjoint();
tmp = R->multiply(tmp, /* H */ false, false);
tmp.conjugate(false);
tmp.transpose();
tmp.adjoint();
tmp *= lambda/c;
D -= tmp;
};
......@@ -185,11 +184,9 @@ void Faust::palm4msa(const Faust::MatDense<FPP,DEVICE>& A,
if(sc.isCriterionErr())
error = tmp.norm();
//TODO: do something to lighten the double transpose conjugate
tmp.conjugate(false);
tmp.transpose();
tmp.adjoint();
tmp = R->multiply(tmp, /* NO H */ false, false);
tmp.conjugate(false);
tmp.transpose();
tmp.adjoint();
tmp = L->multiply(tmp, true, true);
tmp *= lambda/c;
D -= tmp;
......@@ -268,32 +265,9 @@ void Faust::palm4msa2(const Faust::MatDense<FPP,DEVICE>& A,
dims.push_back(make_pair(c->get_rows(), c->get_cols()));
//TODO: make it possible to have a MatSparse A
Faust::MatDense<FPP,DEVICE> A_H = A;
A_H.conjugate(false);
A_H.transpose();
A_H.adjoint();
if(S.size() != nfacts)
{
// S = Faust::TransformHelper<FPP,DEVICE>();
//TODO: refactor the id factor gen. into TransformHelper
for(auto fdims : dims)
{
// init all facts as identity matrices
// with proper dimensions
Faust::MatGeneric<FPP,DEVICE>* fact;
if(use_csr)
{
auto sfact = new Faust::MatSparse<FPP,DEVICE>(fdims.first, fdims.second);
sfact->setEyes();
fact = sfact;
}
else
{
auto dfact = new Faust::MatDense<FPP,DEVICE>(fdims.first, fdims.second);
dfact->setEyes();
fact = dfact;
}
S.push_back(fact); //TODO: copying=false
}
}
fill_of_eyes(S, nfacts, use_csr, dims);
int i = 0, f_id;
std::function<void()> init_ite, next_fid;
std::function<bool()> updating_facs;
......@@ -476,3 +450,33 @@ void Faust::palm4msa2(const Faust::MatDense<FPP,DEVICE>& A,
}
S.update_total_nnz();
}
template <typename FPP, FDevice DEVICE>
void Faust::fill_of_eyes(
Faust::TransformHelper<FPP,DEVICE>& S,
const unsigned int nfacts,
const bool sparse,
const std::vector<std::pair<faust_unsigned_int,faust_unsigned_int>> dims)
{
if(S.size() > 0)
throw std::runtime_error("The Faust must be empty for intializing it to eyes factors.");
for(auto fdims : dims)
{
// init all facts as identity matrices
// with proper dimensions
Faust::MatGeneric<FPP,DEVICE>* fact;
if(sparse)
{
auto sfact = new Faust::MatSparse<FPP,DEVICE>(fdims.first, fdims.second);
sfact->setEyes();
fact = sfact;
}
else
{
auto dfact = new Faust::MatDense<FPP,DEVICE>(fdims.first, fdims.second);
dfact->setEyes();
fact = dfact;
}
S.push_back(fact); //TODO: copying=false
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment