Mentions légales du service

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

Minor fixes about C++ namespaces.

Removing "using namespace" from some headers (more proper).
parent 7c64228e
No related branches found
No related tags found
No related merge requests found
......@@ -33,10 +33,10 @@ int main(int argc, char* argv[])
M_sp1->multiply(*M_sp2, 'N');
M2.multiplyLeft(M1);
cout << "abs err:" << (M2.norm()-M_sp2->norm()) << endl;
assert(Faust::abs(M2.norm()-M_sp2->norm()) < 1.0e-5);
assert(M2.norm()-M_sp2->norm() < 1.0e-5);
M2*=M2;
M_sp2->multiplyRight(*M_sp2);
assert(Faust::abs(M2.norm()-M_sp2->norm()) < 1.0e-5);
assert(M2.norm()-M_sp2->norm() < 1.0e-5);
cout << "abs err2:" << (M2.norm()-M_sp2->norm()) << endl;
return 0;
}
......@@ -5,6 +5,7 @@
#include <complex>
using namespace Faust;
using namespace std;
typedef @TEST_FPP@ FPP;
......
......@@ -4,11 +4,12 @@
#include <vector>
namespace Faust {
template<typename FPP,Device DEVICE> class MatGeneric;
/**
* \brief Fast Walsh-Hadamard Transform.
*/
template<typename FPP>
void wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool cloning_fact=true, const bool norma=false);
void wht_factors(unsigned int n, std::vector<MatGeneric<FPP,Cpu>*>& factors, const bool cloning_fact=true, const bool norma=false);
}
#include "faust_WHT.hpp"
......
......@@ -3,7 +3,7 @@
namespace Faust {
template<typename FPP>
void wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool cloning_fact, const bool norma)
void wht_factors(unsigned int n, std::vector<MatGeneric<FPP,Cpu>*>& factors, const bool cloning_fact, const bool norma)
{
if(n == 0)
{
......@@ -16,8 +16,8 @@ namespace Faust {
{
factors.resize(n);
unsigned int order = 1ull << n;
vector<int> col_ids(order), row_ids(order);
vector<FPP> vals(order);
std::vector<int> col_ids(order), row_ids(order);
std::vector<FPP> vals(order);
unsigned int order_over_2 = order >> 1;
unsigned int order_times_2 = order << 1;
unsigned int i_times_2;
......
......@@ -408,7 +408,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
Faust::Vect<FPP,Cpu> get_row(faust_unsigned_int id) const;
Faust::MatDense<FPP,Cpu>* get_cols(faust_unsigned_int start_col_id, faust_unsigned_int num_cols) const;
Faust::MatDense<FPP,Cpu>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int n) const;
Faust::MatDense<FPP,Cpu>* get_cols(vector<int> col_ids) const;
Faust::MatDense<FPP,Cpu>* get_cols(std::vector<int> col_ids) const;
Faust::MatDense<FPP,Cpu>* get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows) const;
Faust::MatDense<FPP,Cpu>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int n) const;
......@@ -473,7 +473,7 @@ void spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> &
/**
* \brief Returns the nonzeros indices.
*/
list<pair<int,int>> nonzeros_indices() const;
std::list<std::pair<int,int>> nonzeros_indices() const;
private:
Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic> mat;
......
......@@ -163,11 +163,11 @@ Faust::MatDense<FPP,Cpu> Faust::MatDense<FPP,Cpu>::lower_tri(const bool diag) co
else
tri.mat = mat.template triangularView<Eigen::StrictlyLower>();
#ifdef DEBUG_TRI
cout << "MatDense::lower_tri(" << diag << ")" << endl;
cout << "orig. mat.:" << endl;
cout << mat << endl;
cout << "tri. mat.:" << endl;
cout << tri.mat << endl;
std::cout << "MatDense::lower_tri(" << diag << ")" << std::endl;
std::cout << "orig. mat.:" << std::endl;
std::cout << mat << std::endl;
std::cout << "tri. mat.:" << std::endl;
std::cout << tri.mat << std::endl;
#endif
return tri;
}
......@@ -181,23 +181,23 @@ Faust::MatDense<FPP,Cpu> Faust::MatDense<FPP,Cpu>::upper_tri(const bool diag) co
else
tri.mat = mat.template triangularView<Eigen::StrictlyUpper>();
#ifdef DEBUG_TRI
cout << "MatDense::upper_tri(" << diag << ")" << endl;
cout << "orig. mat.:" << endl;
cout << mat << endl;
cout << "tri. mat.:" << endl;
cout << tri.mat << endl;
std::cout << "MatDense::upper_tri(" << diag << ")" << std::endl;
std::cout << "orig. mat.:" << std::endl;
std::cout << mat << std::endl;
std::cout << "tri. mat.:" << std::endl;
std::cout << tri.mat << std::endl;
#endif
return tri;
}
template<typename FPP>
list<pair<int,int>> Faust::MatDense<FPP,Cpu>::nonzeros_indices() const
std::list<std::pair<int,int>> Faust::MatDense<FPP,Cpu>::nonzeros_indices() const
{
list<pair<int,int>> nz_inds;
std::list<std::pair<int,int>> nz_inds;
if(this->is_identity)
for(int i=0;i<min(this->dim1, this->dim2);i++)
nz_inds.push_back(make_pair(i,i));
for(int i=0;i<std::min(this->dim1, this->dim2);i++)
nz_inds.push_back(std::make_pair(i,i));
else if(! isZeros)
{
int i,j;
......@@ -206,7 +206,7 @@ list<pair<int,int>> Faust::MatDense<FPP,Cpu>::nonzeros_indices() const
{
j = k/this->dim1;
i = k-j*this->dim1;
nz_inds.push_back(make_pair(i,j));
nz_inds.push_back(std::make_pair(i,j));
}
}
return nz_inds;
......@@ -704,11 +704,11 @@ std::string Faust::MatDense<FPP,Cpu>::to_string(const bool transpose /* set to f
//using ostringstream because it's easier for concatenation (of complex and any number)
std::ostringstream str;
str << " (" << (typeid(*getData()) == typeid(complex<double>) || typeid(*getData()) == typeid(complex<float>)?"complex":"real") << ")";
str << " (" << (typeid(*getData()) == typeid(std::complex<double>) || typeid(*getData()) == typeid(std::complex<float>)?"complex":"real") << ")";
str<<" DENSE, "; //number of trailing spaces matters to align with SPARSE to_string()
str << Faust::MatGeneric<FPP,Cpu>::to_string(transpose);
if(isZeros)
str <<"zeros matrix flag" << endl;
str <<"zeros matrix flag" << std::endl;
else
{
if (displaying_small_mat_elts && this->dim1*this->dim2 < 100)
......@@ -717,7 +717,7 @@ std::string Faust::MatDense<FPP,Cpu>::to_string(const bool transpose /* set to f
{
for(int j=0 ; j<this->dim2 ; j++)
str << (*this)(i,j) << " " ;
str << endl;
str << std::endl;
}
}
}
......@@ -736,13 +736,13 @@ void Faust::MatDense<FPP,Cpu>::Display() const
template<typename FPP>
void Faust::MatDense<FPP,Cpu>::print_file(const char* filename)const
{
ofstream fichier;
std::ofstream fichier;
fichier.open(filename);
for (int i=0 ; i<this->getNbRow() ; i++)
{
for (int j=0 ; j<this->getNbCol() ; j++)
fichier << setprecision(20) <<mat(i,j) << " ";
fichier << endl;
fichier << std::setprecision(20) <<mat(i,j) << " ";
fichier << std::endl;
}
fichier.close();
}
......@@ -907,12 +907,12 @@ void Faust::MatDense<FPP,Cpu>::init_from_file(const char* filename)
// chacune des autres lignes contient une valeur par ligne
// suivant la premiere dimension puis la deuxieme
ifstream* vec_stream;
vec_stream = new ifstream(filename);
std::ifstream* vec_stream;
vec_stream = new std::ifstream(filename);
if (!vec_stream->is_open())
handleError(m_className, "init_from_file : unable to open file");
istream_iterator<FPP> start(*vec_stream), eos;
vector<FPP> vec(start, eos);
std::istream_iterator<FPP> start(*vec_stream), eos;
std::vector<FPP> vec(start, eos);
if((vec[0]*vec[1]+2) != vec.size())
{
......@@ -935,7 +935,7 @@ matvar_t* Faust::MatDense<FPP, Cpu>::toMatIOVar(bool transpose, bool conjugate)
{
matvar_t *var = NULL;
size_t dims[2];
int opt = typeid(mat(0,0))==typeid(complex<double>(1.0,1.0))?MAT_F_COMPLEX:0;
int opt = typeid(mat(0,0))==typeid(std::complex<double>(1.0,1.0))?MAT_F_COMPLEX:0;
mat_complex_split_t z = {NULL,NULL};
//
if(transpose)
......@@ -1070,7 +1070,7 @@ Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_cols(faust_unsigned_int*
}
template<typename FPP>
Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_cols(vector<int> col_ids) const
Faust::MatDense<FPP,Cpu>* Faust::MatDense<FPP,Cpu>::get_cols(std::vector<int> col_ids) const
{
//TODO: check args
int n = col_ids.size();
......@@ -1272,29 +1272,29 @@ Faust::Timer Faust::MatDense<FPP,Cpu>::t_power_iteration;
template<typename FPP>
void Faust::MatDense<FPP,Cpu>::print_timers()const
{
cout << "timers in Faust::MatDense :" << endl;
cout << "t_constr = " << t_constr.get_time() << " s for "<< t_constr.get_nb_call() << " calls" << endl;
cout << "t_get_coeff = " << t_get_coeff.get_time() << " s for "<< t_get_coeff.get_nb_call() << " calls" << endl;
cout << "t_get_coeffs = " << t_get_coeffs.get_time() << " s for "<< t_get_coeffs.get_nb_call() << " calls" << endl;
cout << "t_set_coeff = " << t_set_coeff.get_time() << " s for "<< t_set_coeff.get_nb_call() << " calls" << endl;
cout << "t_set_coeffs = " << t_set_coeffs.get_time() << " s for "<< t_set_coeffs.get_nb_call() << " calls" << endl;
cout << "t_set_coeffs2 = " << t_set_coeffs2.get_time() << " s for "<< t_set_coeffs2.get_nb_call() << " calls" << endl;
cout << "t_resize = " << t_resize.get_time() << " s for "<< t_resize.get_nb_call() << " calls" << endl;
cout << "t_check_dim = " << t_check_dim.get_time() << " s for "<< t_check_dim.get_nb_call() << " calls" << endl;
cout << "t_max = " << t_max.get_time() << " s for "<< t_max.get_nb_call() << " calls" << endl;
cout << "t_transpose = " << t_transpose.get_time() << " s for "<< t_transpose.get_nb_call() << " calls" << endl;
cout << "t_mult_right = " << t_mult_right.get_time() << " s for "<< t_mult_right.get_nb_call() << " calls" << endl;
cout << "t_mult_left = " << t_mult_left.get_time() << " s for "<< t_mult_left.get_nb_call() << " calls" << endl;
cout << "t_scalar_multiply = " << t_scalar_multiply.get_time() << " s for "<< t_scalar_multiply.get_nb_call() << " calls" << endl;
cout << "t_add = " << t_add.get_time() << " s for "<< t_add.get_nb_call() << " calls" << endl;
cout << "t_sub = " << t_sub.get_time() << " s for "<< t_sub.get_nb_call() << " calls" << endl;
cout << "t_print_file = " << t_print_file.get_time() << " s for "<< t_print_file.get_nb_call() << " calls" << endl<<endl;
cout << "timers in Faust::MatDense / LinearAlgebra :" << endl;
cout << "t_multiply = " << t_multiply.get_time() << " s for "<< t_multiply.get_nb_call() << " calls" << endl;
cout << "t_gemm = " << t_gemm.get_time() << " s for "<< t_gemm.get_nb_call() << " calls" << endl;
cout << "t_add_ext = " << t_add_ext.get_time() << " s for "<< t_add_ext.get_nb_call() << " calls" << endl<<endl<<endl;
std::cout << "timers in Faust::MatDense :" << std::endl;
std::cout << "t_constr = " << t_constr.get_time() << " s for "<< t_constr.get_nb_call() << " calls" << std::endl;
std::cout << "t_get_coeff = " << t_get_coeff.get_time() << " s for "<< t_get_coeff.get_nb_call() << " calls" << std::endl;
std::cout << "t_get_coeffs = " << t_get_coeffs.get_time() << " s for "<< t_get_coeffs.get_nb_call() << " calls" << std::endl;
std::cout << "t_set_coeff = " << t_set_coeff.get_time() << " s for "<< t_set_coeff.get_nb_call() << " calls" << std::endl;
std::cout << "t_set_coeffs = " << t_set_coeffs.get_time() << " s for "<< t_set_coeffs.get_nb_call() << " calls" << std::endl;
std::cout << "t_set_coeffs2 = " << t_set_coeffs2.get_time() << " s for "<< t_set_coeffs2.get_nb_call() << " calls" << std::endl;
std::cout << "t_resize = " << t_resize.get_time() << " s for "<< t_resize.get_nb_call() << " calls" << std::endl;
std::cout << "t_check_dim = " << t_check_dim.get_time() << " s for "<< t_check_dim.get_nb_call() << " calls" << std::endl;
std::cout << "t_max = " << t_max.get_time() << " s for "<< t_max.get_nb_call() << " calls" << std::endl;
std::cout << "t_transpose = " << t_transpose.get_time() << " s for "<< t_transpose.get_nb_call() << " calls" << std::endl;
std::cout << "t_mult_right = " << t_mult_right.get_time() << " s for "<< t_mult_right.get_nb_call() << " calls" << std::endl;
std::cout << "t_mult_left = " << t_mult_left.get_time() << " s for "<< t_mult_left.get_nb_call() << " calls" << std::endl;
std::cout << "t_scalar_multiply = " << t_scalar_multiply.get_time() << " s for "<< t_scalar_multiply.get_nb_call() << " calls" << std::endl;
std::cout << "t_add = " << t_add.get_time() << " s for "<< t_add.get_nb_call() << " calls" << std::endl;
std::cout << "t_sub = " << t_sub.get_time() << " s for "<< t_sub.get_nb_call() << " calls" << std::endl;
std::cout << "t_print_file = " << t_print_file.get_time() << " s for "<< t_print_file.get_nb_call() << " calls" << std::endl<<std::endl;
std::cout << "timers in Faust::MatDense / LinearAlgebra :" << std::endl;
std::cout << "t_multiply = " << t_multiply.get_time() << " s for "<< t_multiply.get_nb_call() << " calls" << std::endl;
std::cout << "t_gemm = " << t_gemm.get_time() << " s for "<< t_gemm.get_nb_call() << " calls" << std::endl;
std::cout << "t_add_ext = " << t_add_ext.get_time() << " s for "<< t_add_ext.get_nb_call() << " calls" << std::endl<<std::endl<<std::endl;
}
#endif
......
......@@ -52,11 +52,10 @@
#include "faust_SpBlasHandle.h"
// modif AL AL
#include "faust_Transform.h"
#include "faust_TransformHelper.h"
#include "matio.h"
#include <random>
#include "faust_WHT.h"
//! \class Faust::MatSparse<FPP,Cpu> faust_MatSparse.h
//! \brief Class template representing sparse matrix <br>
//! This class implements sparse matrix multiplication <br>
......@@ -77,22 +76,13 @@ template<typename FPP,Device DEVICE> class Transform;
template<Device DEVICE> class SpBlasHandle;
template<typename FPP>
void Faust::multiply(const Faust::Transform<FPP,Cpu> & A, const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult);
//! modif NB v1102 : comment useless function
template<typename FPP>
void Faust::spgemm(const Faust::MatSparse<FPP,Cpu> & A,const Faust::MatDense<FPP,Cpu> & B, Faust::MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
template<typename FPP>
void Faust::wht_factors(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool, const bool);
//! \namespace Faust
//! \brief Faust namespace contains the principal class of the project.
namespace Faust
{
template<typename FPP,Device DEVICE> class TransformHelper;
template<typename FPP,Device DEVICE> class MatGeneric;
......@@ -104,6 +94,16 @@ namespace Faust
template<typename FPP, Device DEVICE, typename FPP2> class GivensFGFTParallel;
template<typename FPP, Device DEVICE, typename FPP2> class GivensFGFTComplex;
//TODO: simplify/remove the friendship by adding/using a public setter to is_ortho
//template<typename FPP> void wht_factors(unsigned int n, std::vector<MatGeneric<FPP,Cpu>*>& factors, const bool, const bool);
template<typename FPP>
void multiply(const Transform<FPP,Cpu> & A, const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, char typeA, char typeMult);
//! modif NB v1102 : comment useless function
template<typename FPP>
void spgemm(const MatSparse<FPP,Cpu> & A,const MatDense<FPP,Cpu> & B, MatDense<FPP,Cpu> & C,const FPP & alpha, const FPP & beta, char typeA, char typeB);
template<typename FPP>
class MatSparse<FPP,Cpu> : public Faust::MatGeneric<FPP,Cpu>
......@@ -116,7 +116,7 @@ namespace Faust
friend Faust::GivensFGFTComplex<FPP,Cpu, double>;
friend Faust::GivensFGFTComplex<FPP,Cpu, float>;
friend Faust::TransformHelper<FPP,Cpu>; // TODO: limit to needed member functions only
friend void Faust::wht_factors<>(unsigned int n, vector<MatGeneric<FPP,Cpu>*>& factors, const bool, const bool);
friend void Faust::wht_factors<>(unsigned int n, std::vector<MatGeneric<FPP,Cpu>*>& factors, const bool, const bool);
friend class MatDense<FPP,Cpu>;
//friend void MatDense<FPP,Cpu>::operator+=(const MatSparse<FPP,Cpu>& S);
......@@ -315,7 +315,7 @@ namespace Faust
Faust::MatSparse<FPP,Cpu>* get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const;
Faust::MatSparse<FPP,Cpu>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const;
list<pair<int,int>> nonzeros_indices() const;
std::list<std::pair<int,int>> nonzeros_indices() const;
static MatSparse<FPP, Cpu>* randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols, double density);
//\param : per_row means the density applies for each line rather than globally for the matrix
......
......@@ -47,6 +47,7 @@
#include "faust_exception.h"
#include "faust_Transform.h"
#include "faust_Slice.h"
#include "faust_MatSparse.h"
#include <random>
namespace Faust {
......@@ -55,7 +56,7 @@ namespace Faust {
template<typename FPP,Device DEVICE> class Transform;
template<typename FPP,Device DEVICE> class Vect;
template<typename FPP,Device DEVICE> class MatDense;
template<typename FPP,Device DEVICE> class TransformHelper;
template<typename FPP,Device DEVICE> class MatGeneric;
enum RandFaustType {
DENSE,
......
......@@ -103,8 +103,8 @@ template<typename FPP>
class Vect<FPP,Cpu>
{
template<class,Device> friend class Vect;
friend double Faust::Transform<FPP,Cpu>::normL1(const bool transpose) const;
friend Vect<FPP,Cpu> Faust::MatDiag<FPP>::multiply(const Vect<FPP,Cpu> & vec) const;
friend double Transform<FPP,Cpu>::normL1(const bool transpose) const;
friend Vect<FPP,Cpu> MatDiag<FPP>::multiply(const Vect<FPP,Cpu> & vec) const;
friend void MatDiag<FPP>::multiply(Vect<FPP,Cpu> & vec, char opThis) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment