Mentions légales du service

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

Add containsNaN functions in MatGeneric<Cpu> and subclasses.

parent 9137b947
Branches
Tags
No related merge requests found
...@@ -518,6 +518,8 @@ namespace Faust ...@@ -518,6 +518,8 @@ namespace Faust
*/ */
void set_row_coeffs(faust_unsigned_int row_id, const std::vector<int> &col_ids, const MatDense<FPP, Cpu> &values, faust_unsigned_int val_row_id); void set_row_coeffs(faust_unsigned_int row_id, const std::vector<int> &col_ids, const MatDense<FPP, Cpu> &values, faust_unsigned_int val_row_id);
bool containsNaN();
private: private:
Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic> mat; Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic> mat;
bool isZeros; bool isZeros;
......
...@@ -1101,6 +1101,20 @@ void MatDense<FPP,Cpu>::normalize() ...@@ -1101,6 +1101,20 @@ void MatDense<FPP,Cpu>::normalize()
throw std::domain_error("the norm is zero, can't normalize"); throw std::domain_error("the norm is zero, can't normalize");
} }
template<typename FPP>
bool MatDense<FPP,Cpu>::containsNaN()
{
#if(EIGEN_WORLD_VERSION > 3 || EIGEN_WORLD_VERSION >= 3 && EIGEN_MAJOR_VERSION >= 3)
return Eigen::isnan(mat.array()).any();
#else
for(int i=0;i < this->dim1*this->dim2;i++)
if(std::isnan(std::real(getData()[i])))
return true;
return false;
#endif
}
template<typename FPP> template<typename FPP>
void MatDense<FPP,Cpu>::copyBuf(FPP* dst_buf) const void MatDense<FPP,Cpu>::copyBuf(FPP* dst_buf) const
{ {
...@@ -1284,12 +1298,13 @@ bool MatDense<FPP,Cpu>::eq_rows(const MatDense<FPP, Cpu> & other, faust_unsigned ...@@ -1284,12 +1298,13 @@ bool MatDense<FPP,Cpu>::eq_rows(const MatDense<FPP, Cpu> & other, faust_unsigned
template<typename FPP> template<typename FPP>
void MatDense<FPP, Cpu>::best_low_rank(const int &r, MatDense<FPP,Cpu> &bestX, MatDense<FPP, Cpu> &bestY) const void MatDense<FPP, Cpu>::best_low_rank(const int &r, MatDense<FPP,Cpu> &bestX, MatDense<FPP, Cpu> &bestY) const
{ {
#ifdef _MSC_VER #if(EIGEN_WORLD_VERSION > 3 || EIGEN_WORLD_VERSION >= 3 && EIGEN_MAJOR_VERSION >= 3)
Eigen::BDCSVD<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> svd(this->mat, Eigen::ComputeThinU | Eigen::ComputeThinV);
#else
//#ifdef _MSC_VER
// as far as I tested eigen3.4rc1 doesn't compile with VS 14 // as far as I tested eigen3.4rc1 doesn't compile with VS 14
// so use JacobiSVD // so use JacobiSVD
Eigen::JacobiSVD<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> svd(this->mat, Eigen::ComputeThinU | Eigen::ComputeThinV); Eigen::JacobiSVD<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> svd(this->mat, Eigen::ComputeThinU | Eigen::ComputeThinV);
#else
Eigen::BDCSVD<Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic>> svd(this->mat, Eigen::ComputeThinU | Eigen::ComputeThinV);
#endif #endif
if(bestX.getNbRow() != this->getNbRow() || r != bestX.getNbCol()) if(bestX.getNbRow() != this->getNbRow() || r != bestX.getNbCol())
bestX.resize(this->getNbRow(), r); bestX.resize(this->getNbRow(), r);
......
...@@ -93,6 +93,7 @@ namespace Faust ...@@ -93,6 +93,7 @@ namespace Faust
void Display() const; void Display() const;
void setZeros(); void setZeros();
bool containsNaN();
const FPP* getData() const { return mat.diagonal().data();}; const FPP* getData() const { return mat.diagonal().data();};
}; };
......
...@@ -191,3 +191,13 @@ void Faust::MatDiag<FPP>::setZeros() ...@@ -191,3 +191,13 @@ void Faust::MatDiag<FPP>::setZeros()
isZeros = true; isZeros = true;
this->is_identity = false; this->is_identity = false;
} }
template<typename FPP>
bool Faust::MatDiag<FPP>::containsNaN()
{
for(int i=0;i < min(this->dim1, this->dim2);i++)
if(std::isnan(std::real(getData()[i])))
return true;
return false;
}
...@@ -404,6 +404,7 @@ namespace Faust ...@@ -404,6 +404,7 @@ namespace Faust
void real(MatSparse<Real<FPP>, Cpu> & real_mat) const; void real(MatSparse<Real<FPP>, Cpu> & real_mat) const;
bool containsNaN();
void print_bufs(const std::string name=""); void print_bufs(const std::string name="");
void print_asarray(const std::string name=""); void print_asarray(const std::string name="");
static MatSparse<FPP, Cpu>* randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols, Real<FPP> density); static MatSparse<FPP, Cpu>* randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols, Real<FPP> density);
......
...@@ -1443,4 +1443,13 @@ void Faust::MatSparse<FPP,Cpu>::real(MatSparse<Real<FPP>, Cpu> &real_mat) const ...@@ -1443,4 +1443,13 @@ void Faust::MatSparse<FPP,Cpu>::real(MatSparse<Real<FPP>, Cpu> &real_mat) const
real_mat.resize(this->nnz, this->getNbRow(), this->getNbCol()); real_mat.resize(this->nnz, this->getNbRow(), this->getNbCol());
real_mat.mat = mat.real().eval().template cast<Real<FPP>>(); real_mat.mat = mat.real().eval().template cast<Real<FPP>>();
} }
template<typename FPP>
bool Faust::MatSparse<FPP,Cpu>::containsNaN()
{
for(int i=0;i < getNonZeros();i++)
if(std::isnan(std::real(getValuePtr()[i])))
return true;
return false;
}
#endif #endif
...@@ -208,11 +208,13 @@ namespace Faust ...@@ -208,11 +208,13 @@ namespace Faust
void set_id(const bool is_identity) { this->is_identity = is_identity; /* TODO: move def in hpp*/} void set_id(const bool is_identity) { this->is_identity = is_identity; /* TODO: move def in hpp*/}
virtual void setZeros()=0; virtual void setZeros()=0;
virtual bool containsNaN()=0;
virtual const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const =0; virtual const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const =0;
bool is_orthogonal() { return this->is_ortho; /* TODO: move def in hpp*/} bool is_orthogonal() { return this->is_ortho; /* TODO: move def in hpp*/}
bool is_id() const { return this->is_identity; /* TODO: move def in hpp*/} bool is_id() const { return this->is_identity; /* TODO: move def in hpp*/}
//! \brief //! \brief
//! \warning : declare a virtual destructor is mandatory for an abstract class //! \warning : declare a virtual destructor is mandatory for an abstract class
//! in order to allow descendant class destructor to clean up in case of pointer to the abstract class //! in order to allow descendant class destructor to clean up in case of pointer to the abstract class
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment