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
*/
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:
Eigen::Matrix<FPP, Eigen::Dynamic, Eigen::Dynamic> mat;
bool isZeros;
......
......@@ -1101,6 +1101,20 @@ void MatDense<FPP,Cpu>::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>
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
template<typename FPP>
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
// so use JacobiSVD
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
if(bestX.getNbRow() != this->getNbRow() || r != bestX.getNbCol())
bestX.resize(this->getNbRow(), r);
......
......@@ -93,6 +93,7 @@ namespace Faust
void Display() const;
void setZeros();
bool containsNaN();
const FPP* getData() const { return mat.diagonal().data();};
};
......
......@@ -191,3 +191,13 @@ void Faust::MatDiag<FPP>::setZeros()
isZeros = true;
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
void real(MatSparse<Real<FPP>, Cpu> & real_mat) const;
bool containsNaN();
void print_bufs(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);
......
......@@ -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.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
......@@ -208,11 +208,13 @@ namespace Faust
void set_id(const bool is_identity) { this->is_identity = is_identity; /* TODO: move def in hpp*/}
virtual void setZeros()=0;
virtual bool containsNaN()=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_id() const { return this->is_identity; /* TODO: move def in hpp*/}
//! \brief
//! \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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment