Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 59bfa111 authored by hhakim's avatar hhakim
Browse files

Add C++ tests (misc directory) for new implementations Faust::hierarchical,...

Add C++ tests (misc directory) for new implementations Faust::hierarchical, Faust::palm4msa and a new test to factorize Hadamard matrix with the 2016 implementation (Faust::HierarchicalFact) in order to compare with the new implementati
on.

- The tests hierarchica2020Hadamard and hierarchicalFactorizationHadamard receive optional argument to define the Hadamard matrix dimension.
- The test palm4msa2020 receives an argument to choose the implementation to run (Faust::palm4msa or Faust::palm4msa2).
parent 8e65979c
No related branches found
No related tags found
No related merge requests found
......@@ -199,7 +199,7 @@ if(MATIO_LIB_FILE AND MATIO_INC_DIR AND BUILD_READ_MAT_FILE AND NOT NOCPPTESTS)
foreach(TEST_FPP float double complex<float> complex<double>)
foreach(testin hierarchicalFactorization hierarchicalFactorizationFFT test_palm4MSA test_palm4MSAFFT faust_multiplication faust_matdense_conjugate GivensFGFT GivensFGFTSparse GivensFGFTParallel GivensFGFTParallelSparse test_MatDiag faust_matsparse_mul faust_matsparse_index_op GivensFGFTComplex GivensFGFTComplexSparse GivensFGFTParallelComplex faust_toeplitz faust_circ faust_hankel)
foreach(testin hierarchicalFactorization hierarchicalFactorizationFFT test_palm4MSA test_palm4MSAFFT faust_multiplication faust_matdense_conjugate GivensFGFT GivensFGFTSparse GivensFGFTParallel GivensFGFTParallelSparse test_MatDiag faust_matsparse_mul faust_matsparse_index_op GivensFGFTComplex GivensFGFTComplexSparse GivensFGFTParallelComplex faust_toeplitz faust_circ faust_hankel palm4msa_2020 hierarchical2020 hierarchical2020Hadamard hierarchicalFactorizationHadamard )
if(${TEST_FPP} MATCHES complex )
set(TEST_IS_COMPLEX 1)
if(${testin} MATCHES GivensFGFT)
......
/****************************************************************************/
/* Description: */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2020): Hakim H., 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: */
/* 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 "faust_MatSparse.h"
#include "faust_Timer.h"
#include "faust_Transform.h"
#include "faust_TransformHelper.h"
#include "faust_init_from_matio_params.h"
#include "faust_init_from_matio_core.h"
#include <string>
#include <sstream>
#include "faust_BlasHandle.h"
#include "faust_SpBlasHandle.h"
#include "faust_HierarchicalFact.h"
#include "faust_hierarchical.h"
#include <iostream>
#include <iomanip>
/** \brief An example of using the hierarchical factorization of a dense matrix. from .mat file.
* An dense matrix is loaded from "@FAUST_DATA_MAT_DIR@
* \param MatrixFilename : a .mat (MATLAB file) where the matrix to be factorized is stored (or its transposed (cf. parameter transposeMatrix))
* \param configFilename : a .mat (MATLAB file) configuration file which contains the parameter of the hierarchical algorithm (default launch with a predefined configuration called hierFact)
* \param expectedLambda (optionnal) : compared the expected scalar of the factorisation with the computed one in the precision defined with epsilon
*\param epsilon (optionnal) : precision for the test of equality (default value 0.0001)
*\param transposeMatrix (optionnal) : -value 'N' (default value), the matrix stored in MatrixFilename is factorized
-value 'T' , the transposed matrix is factorized
*/
typedef @TEST_FPP@ FPP;
typedef @TEST_FPP2@ FPP2;
void create_matrix(Faust::MatDense<complex<FPP2>,Cpu>& data, Faust::MatDense<complex<FPP2>,Cpu>& idata)
{
idata = data;
idata.scalarMultiply(complex<FPP2>(0,1));
data += idata;
}
void create_matrix(Faust::MatDense<FPP2,Cpu>& data, Faust::MatDense<FPP2,Cpu>& idata)
{
//nothing to do
}
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
//default value
string configFilename = "@FAUST_CONFIG_MAT_DIR@/config_hierarchical_fact.mat";
string MatrixFilename = "@FAUST_DATA_MAT_DIR@/matrix_hierarchical_fact.mat";
if (argc >= 3)
{
MatrixFilename = argv[1];
configFilename = argv[2];
}
FPP expectedLambda = 0;
if (argc >= 4)
expectedLambda = atof(argv[3]);
FPP2 epsilon = 0.0001;
if (argc >= 5)
epsilon = atof(argv[4]);
char transposedMatrix='N';
if (argc >= 6)
transposedMatrix=argv[5][0];
if ((transposedMatrix != 'N') && (transposedMatrix != 'T'))
{
cerr << "transposedMatrix value is "<<transposedMatrix<< endl;
cerr << "transposedMatrix parameter must be equal to ''N'' or ''T'' " << endl;
exit(EXIT_FAILURE);
}
size_t ind = configFilename.find_last_of(".");
if(ind<=0 || ind>= configFilename.size())
{
cerr << "Le nom du fichier est incorrect" << endl;
exit(EXIT_FAILURE);
}
string configFileExtension(configFilename, ind);
if(configFileExtension.compare(".mat") != 0)
{
cerr << "Le nom du fichier doit se terminer par \".mat\"" << endl;
exit(EXIT_FAILURE);
}
string configFileBodyTmp(configFilename, 0, ind);
string configFileBodyDir, configFileBodyFile;
ind = configFileBodyTmp.find_last_of("/");
if(ind<=0 || ind>= configFileBodyTmp.size())
{
configFileBodyDir = string("");
configFileBodyFile = configFileBodyTmp;
}
else
{
configFileBodyDir = string(configFileBodyTmp, 0, ind+1);
configFileBodyFile = string(configFileBodyTmp, ind+1);
}
// useless for CPU but use for compatibility with GPU
Faust::BlasHandle<Cpu> blasHandle;
Faust::SpBlasHandle<Cpu> spblasHandle;
// parameter setting
Faust::Params<FPP,Cpu,FPP2> params;
init_params_from_matiofile<FPP,Cpu,FPP2>(params,configFilename.c_str(),"params");
params.Display();
// matrix to be factorized
Faust::MatDense<FPP,Cpu> matrix, imatrix;
init_faust_mat_from_matio(matrix,MatrixFilename.c_str(),"matrix");
create_matrix(matrix, imatrix);
// transposed the matrix if needed
if (transposedMatrix == 'T')
matrix.transpose();
//algorithm
auto cons = params.cons;
auto fac_cons = cons[0];
auto res_cons = cons[1];
Real<FPP> lambda;
auto th = Faust::hierarchical(matrix, 200, fac_cons, res_cons, lambda, params.isUpdateWayR2L,
params.isFactSideLeft, true);
cout << "lambda=" << lambda << endl;
th->multiply(lambda);
th->display();
//relativeError
Faust::MatDense<FPP,Cpu> faustProduct;
faustProduct=th->get_product(); // TransformHelper
faustProduct *= FPP(lambda);
faustProduct-=matrix;
cout << th->normFro() << endl;
FPP2 relativeError = Faust::fabs(faustProduct.norm()/matrix.norm());
std::cout<<std::endl;
std::cout<<"**************** RELATIVE ERROR BETWEEN FAUST AND DATA MATRIX **************** "<<std::endl;
std::cout<<" "<<relativeError<<std::endl<<std::endl;
blasHandle.Destroy();
spblasHandle.Destroy();
return 0;
}
/****************************************************************************/
/* Description: */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2020): Hakim H., 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: */
/* 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 "faust_MatSparse.h"
#include "faust_Timer.h"
#include "faust_Transform.h"
#include "faust_TransformHelper.h"
#include "faust_init_from_matio_params.h"
#include "faust_init_from_matio_core.h"
#include <string>
#include <sstream>
#include "faust_BlasHandle.h"
#include "faust_SpBlasHandle.h"
#include "faust_HierarchicalFact.h"
#include "faust_hierarchical.h"
#include "faust_ConstraintGeneric.h"
#include "faust_ConstraintInt.h"
#include <iostream>
#include <iomanip>
#include <vector>
/** \brief An example of using the hierarchical factorization of a dense matrix. from .mat file.
* An dense matrix is loaded from "@FAUST_DATA_MAT_DIR@
* \param MatrixFilename : a .mat (MATLAB file) where the matrix to be factorized is stored (or its transposed (cf. parameter transposeMatrix))
* \param configFilename : a .mat (MATLAB file) configuration file which contains the parameter of the hierarchical algorithm (default launch with a predefined configuration called hierFact)
* \param expectedLambda (optionnal) : compared the expected scalar of the factorisation with the computed one in the precision defined with epsilon
*\param epsilon (optionnal) : precision for the test of equality (default value 0.0001)
*\param transposeMatrix (optionnal) : -value 'N' (default value), the matrix stored in MatrixFilename is factorized
-value 'T' , the transposed matrix is factorized
*/
typedef @TEST_FPP@ FPP;
typedef @TEST_FPP2@ FPP2;
using namespace Faust;
using namespace std;
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
int dim = 32;
if(argc > 1)
dim = std::stoi(string(argv[1]));
int log2dim = log2(dim);
auto wht = TransformHelper<FPP,Cpu>::hadamardFaust(log2dim);
auto whtmat = wht->get_product();
vector<const Faust::ConstraintGeneric*> fac_cons, res_cons;
//algorithm
for(int i=0;i<log2dim-1;i++)
{
auto cons = new Faust::ConstraintInt<FPP,Cpu>(CONSTRAINT_NAME_SPLINCOL, 2, dim,
dim);
fac_cons.push_back(cons);
auto rcons = new Faust::ConstraintInt<FPP,Cpu>(CONSTRAINT_NAME_SPLINCOL, dim/(1<<(i+1)), dim, dim);
res_cons.push_back(rcons);
}
Real<FPP> lambda;
bool isUpdateWayR2L = true, isFactSideLeft = false, use_csr = true;
char* str_norm2_threshold = getenv("NORM2_THRESHOLD");
char* str_norm2_max_iter = getenv("NORM2_MAX_ITER");
double norm2_threshold = FAUST_PRECISION;
double norm2_max_iter = FAUST_NORM2_MAX_ITER;
if(str_norm2_threshold)
norm2_threshold = std::atof(str_norm2_threshold);
if(str_norm2_max_iter)
norm2_max_iter = std::atoi(str_norm2_max_iter);
cout << "norm2_threshold: "<< norm2_threshold << endl;
cout << "norm2_max_iter:" << norm2_max_iter << endl;
auto th = Faust::hierarchical(whtmat, 30, fac_cons, res_cons, lambda, isUpdateWayR2L,
isFactSideLeft, use_csr,
/* compute_2norm_on_array*/ false,
norm2_threshold,
norm2_max_iter);
cout << "lambda=" << lambda << endl;
// th->multiply(FPP(lambda));
th->display();
//relativeError
Faust::MatDense<FPP,Cpu> faustProduct;
faustProduct=th->get_product(); // TransformHelper
faustProduct *= FPP(lambda);
faustProduct-=whtmat;
cout << th->normFro() << endl;
FPP2 relativeError = Faust::fabs(faustProduct.norm()/whtmat.norm());
std::cout<<std::endl;
std::cout<<"**************** RELATIVE ERROR BETWEEN FAUST AND DATA MATRIX **************** "<<std::endl;
std::cout<<" "<<relativeError<<std::endl<<std::endl;
return 0;
}
/****************************************************************************/
/* Description: */
/* For more information on the FAuST Project, please visit the website */
/* of the project : <http://faust.inria.fr> */
/* */
/* License: */
/* Copyright (2020): Hakim H., 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: */
/* 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 "faust_MatSparse.h"
#include "faust_Timer.h"
#include "faust_Transform.h"
#include "faust_TransformHelper.h"
#include "faust_init_from_matio_params.h"
#include "faust_init_from_matio_core.h"
#include <string>
#include <sstream>
#include "faust_BlasHandle.h"
#include "faust_SpBlasHandle.h"
#include "faust_HierarchicalFact.h"
#include "faust_hierarchical.h"
#include "faust_ConstraintGeneric.h"
#include "faust_ConstraintInt.h"
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
/** \brief An example of using the hierarchical factorization of a dense matrix. from .mat file.
* An dense matrix is loaded from "@FAUST_DATA_MAT_DIR@
* \param MatrixFilename : a .mat (MATLAB file) where the matrix to be factorized is stored (or its transposed (cf. parameter transposeMatrix))
* \param configFilename : a .mat (MATLAB file) configuration file which contains the parameter of the hierarchical algorithm (default launch with a predefined configuration called hierFact)
*\param epsilon (optionnal) : precision for the test of equality (default value 0.0001)
*\param transposeMatrix (optionnal) : -value 'N' (default value), the matrix stored in MatrixFilename is factorized
-value 'T' , the transposed matrix is factorized
*/
typedef @TEST_FPP@ FPP;
typedef @TEST_FPP2@ FPP2;
using namespace Faust;
using namespace std;
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
int dim = 32;
if(argc > 1)
dim = std::stoi(string(argv[1]));
int log2dim = log2(dim);
auto wht = TransformHelper<FPP,Cpu>::hadamardFaust(log2dim);
auto whtmat = wht->get_product();
vector<const Faust::ConstraintGeneric*> fac_cons, res_cons;
//algorithm
for(int i=0;i<log2dim-1;i++)
{
auto fcons = new Faust::ConstraintInt<FPP,Cpu>(CONSTRAINT_NAME_SPLINCOL, 2, dim,
dim);
fac_cons.push_back(fcons);
auto rcons = new Faust::ConstraintInt<FPP,Cpu>(CONSTRAINT_NAME_SPLINCOL, dim/(1<<(i+1)), dim, dim);
res_cons.push_back(rcons);
}
FPP lambda;
bool isUpdateWayR2L = true, isFactSideLeft = false;
StoppingCriterion<Real<FPP>> s1(30);
StoppingCriterion<Real<FPP>> s2(30);
vector<vector<const Faust::ConstraintGeneric*>> cons;
cons.push_back(fac_cons);
cons.push_back(res_cons);
// for(auto ite=fac_cons.begin();ite != fac_cons.end(); ite++)
// cons.push_back(*ite);
// for(auto ite=res_cons.begin();ite != res_cons.end(); ite++)
// cons.push_back(*ite);
// parameter setting
Faust::Params<FPP,Cpu,FPP2> params;
params.m_nbFact = log2dim;
params.m_nbRow = params.m_nbCol = dim;
params.isVerbose = false;
params.isUpdateWayR2L = isUpdateWayR2L;
params.isFactSideLeft = isFactSideLeft;
params.cons = cons;
params.stop_crit_2facts = s1;
params.stop_crit_global = s2;
vector<Faust::MatDense<FPP,Cpu>> ini_facs;
for(int i=0;i<log2dim;i++)
ini_facs.push_back(Faust::MatDense<FPP,Cpu>());
params.init_fact = ini_facs;
char* str_norm2_threshold = getenv("NORM2_THRESHOLD");
char* str_norm2_max_iter = getenv("NORM2_MAX_ITER");
if(str_norm2_threshold)
params.norm2_threshold = std::atof(str_norm2_threshold);
if(str_norm2_max_iter)
params.norm2_max_iter = std::atoi(str_norm2_max_iter);
params.Display();
// useless for CPU but use for compatibility with GPU
Faust::BlasHandle<Cpu> blasHandle;
Faust::SpBlasHandle<Cpu> spblasHandle;
// auto th = Faust::hierarchical(whtmat, 30, fac_cons, res_cons, lambda, isUpdateWayR2L,
// isFactSideLeft, use_csr);
Faust::HierarchicalFact<FPP,Cpu,FPP2> hierFact(whtmat,params, blasHandle, spblasHandle);
hierFact.compute_facts();
Faust::Transform<FPP,Cpu> t;
hierFact.get_facts(t);
lambda = hierFact.get_lambda();
auto th = new TransformHelper<FPP,Cpu>(t);
cout << "lambda=" << lambda << endl;
// th = th->multiply(lambda);
th->display();
//relativeError
Faust::MatDense<FPP,Cpu> faustProduct;
faustProduct=th->get_product(); // TransformHelper
faustProduct *= lambda;
faustProduct-=whtmat;
cout << th->normFro() << endl;
FPP2 relativeError = Faust::fabs(faustProduct.norm()/whtmat.norm());
std::cout<<std::endl;
std::cout<<"**************** RELATIVE ERROR BETWEEN FAUST AND DATA MATRIX **************** "<<std::endl;
std::cout<<" "<<relativeError<<std::endl<<std::endl;
return 0;
}
/* Copyright (2016): 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: */
/* 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-01167958v1> */
/****************************************************************************/
#include "matio.h"
#include "faust_palm4msa.h"
#include <string>
#include <chrono>
#include "faust_init_from_matio.h"
#include "faust_init_from_matio_mat.h"
typedef @TEST_FPP@ FPP;
using namespace Faust;
using namespace std;
int main(int argc, char* argv[])
{
if (typeid(FPP) == typeid(double))
{
cout<<"floating point precision == double"<<endl;
}
if (typeid(FPP) == typeid(float))
{
cout<<"floating point precision == float"<<endl;
}
Faust::MatDense<FPP,Cpu> data;
char configPalm2Filename[] = "@FAUST_DATA_MAT_DIR@/config_compared_palm2.mat";
init_faust_mat_from_matio(data, configPalm2Filename, "data");
Faust::ConstraintInt<FPP,Cpu> c1(CONSTRAINT_NAME_SPLIN, 5, 500, 32);
Faust::ConstraintFPP<FPP, Cpu, Real<FPP>> c2(CONSTRAINT_NAME_NORMCOL, 1.0, 32, 32);
// vector<MatGeneric<FPP,Cpu>*> facts;
TransformHelper<FPP,Cpu> facts;
vector<ConstraintGeneric*> constraints{&c1, &c2};
Real<FPP> lambda= 1;
// TransformHelper<FPP,Cpu>* th = TransformHelper<FPP,Cpu>::hadamardFaust(5);
// th->display();
// MatDense<FPP,Cpu> H = th->get_product();
// H.Display();
// palm4msa<FPP,Cpu>(H, constraints, facts, lambda, 30, true);
// MatDense<FPP, Cpu>* H = Faust::MatDense<FPP,Cpu>::randMat(500,32);
// H->Display();
data.Display();
bool use_csr = false, is_update_way_R2L = false;
int nites = 200;
bool compute_2norm_on_array = false;
Real<FPP> norm2_threshold = 10e-16;
int norm2_max_iter = 1000;
if(argc > 1)
{
cout << "use impl1" << endl;
Faust::palm4msa<FPP,Cpu>(data, constraints, facts, lambda, nites, is_update_way_R2L, use_csr, compute_2norm_on_array, norm2_threshold, norm2_max_iter);
}
else
{
cout << "use impl2" << endl;
Faust::palm4msa2<FPP,Cpu>(data, constraints, facts, lambda, nites, is_update_way_R2L, use_csr, compute_2norm_on_array, norm2_threshold, norm2_max_iter);
}
// auto left_th_2 = th->left(2);
// left_th_2->display();
//
// auto right_th_2 = th->right(3);
// right_th_2->display();
facts.display();
cout << "out lambda: " << lambda << endl;
Faust::MatDense<FPP,Cpu> faustProduct;
faustProduct=facts.get_product();
faustProduct *= FPP(lambda);
faustProduct-=data;
Real<FPP> relativeError = fabs(faustProduct.norm()/data.norm());
std::cout<<std::endl;
std::cout<<"**************** RELATIVE ERROR BETWEEN FAUST AND DATA MATRIX **************** "<<std::endl;
std::cout<< "\t\t" << relativeError<<std::endl<<std::endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment