Mentions légales du service

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

Add MatGeneric<FPP,Cpu>::getNBytes() and subclass impls + refactor...

Add MatGeneric<FPP,Cpu>::getNBytes() and subclass impls + refactor TransformHelperGen::optimize_storage.
parent 5721be1c
No related branches found
No related tags found
No related merge requests found
...@@ -454,6 +454,7 @@ namespace Faust ...@@ -454,6 +454,7 @@ namespace Faust
Vect<FPP, Cpu> adiagonal(int index); Vect<FPP, Cpu> adiagonal(int index);
Vect<FPP, Cpu> gen_diagonal(int index, bool diag /* true for diagonal, false for anti-diagonal*/); Vect<FPP, Cpu> gen_diagonal(int index, bool diag /* true for diagonal, false for anti-diagonal*/);
size_t getNBytes() const;
/** /**
* \brief Returns the nonzeros indices. * \brief Returns the nonzeros indices.
......
...@@ -137,6 +137,11 @@ namespace Faust ...@@ -137,6 +137,11 @@ namespace Faust
} }
template<typename FPP>
size_t MatDense<FPP,Cpu>::getNBytes() const
{
return this->getNbCol()*this->getNbRow()*sizeof(FPP);
}
template<typename FPP> template<typename FPP>
void MatDense<FPP,Cpu>::check_dim_validity() void MatDense<FPP,Cpu>::check_dim_validity()
......
...@@ -69,6 +69,7 @@ namespace Faust ...@@ -69,6 +69,7 @@ namespace Faust
void adjoint() { conjugate(true); transpose(); } void adjoint() { conjugate(true); transpose(); }
faust_unsigned_int getNonZeros() const { return mat.diagonal().nonZeros(); } faust_unsigned_int getNonZeros() const { return mat.diagonal().nonZeros(); }
size_t getNBytes() const;
matvar_t* toMatIOVar(bool transpose, bool conjugate) const; matvar_t* toMatIOVar(bool transpose, bool conjugate) const;
Real<FPP> normL1(const bool transpose=false) const; Real<FPP> normL1(const bool transpose=false) const;
typename Eigen::NumTraits<FPP>::Real norm() const; typename Eigen::NumTraits<FPP>::Real norm() const;
......
...@@ -182,3 +182,8 @@ std::list<std::pair<int,int>> Faust::MatDiag<FPP>::nonzeros_indices() const ...@@ -182,3 +182,8 @@ std::list<std::pair<int,int>> Faust::MatDiag<FPP>::nonzeros_indices() const
return nz_inds; return nz_inds;
} }
template<typename FPP>
size_t Faust::MatDiag<FPP>::getNBytes() const
{
sizeof(FPP)*this->dim1*this->dim2;
}
...@@ -205,6 +205,7 @@ namespace Faust ...@@ -205,6 +205,7 @@ namespace Faust
//int getNbRow()const{return this->dim1;} //int getNbRow()const{return this->dim1;}
//int getNbCol()const{return this->dim2;} //int getNbCol()const{return this->dim2;}
faust_unsigned_int getNonZeros()const{return nnz;} faust_unsigned_int getNonZeros()const{return nnz;}
size_t getNBytes() const;
bool isCompressedMode()const{return mat.isCompressed();} bool isCompressedMode()const{return mat.isCompressed();}
void makeCompression(){mat.makeCompressed();} void makeCompression(){mat.makeCompressed();}
......
...@@ -1139,4 +1139,12 @@ void Faust::MatSparse<FPP,Cpu>::swap_cols(faust_unsigned_int id1, faust_unsigned ...@@ -1139,4 +1139,12 @@ void Faust::MatSparse<FPP,Cpu>::swap_cols(faust_unsigned_int id1, faust_unsigned
*this = dmat; *this = dmat;
} }
template<typename FPP>
size_t Faust::MatSparse<FPP,Cpu>::getNBytes() const
{
return this->getNonZeros()*(sizeof(FPP)+sizeof(int))+(this->getNbRow()+1)*sizeof(int);
}
#endif #endif
...@@ -140,6 +140,8 @@ namespace Faust ...@@ -140,6 +140,8 @@ namespace Faust
//! \brief return the number of non-zeros element in the matrix //! \brief return the number of non-zeros element in the matrix
virtual faust_unsigned_int getNonZeros()const=0; virtual faust_unsigned_int getNonZeros()const=0;
virtual size_t getNBytes() const=0;
//!brief return the percentage of non-zeros coefficient in the matrix, //!brief return the percentage of non-zeros coefficient in the matrix,
//! \return value between 0 and 1 //! \return value between 0 and 1
float density() const{return ((float) this->getNonZeros())/((float)this->getNbCol()*this->getNbRow());} float density() const{return ((float) this->getNonZeros())/((float)this->getNbCol()*this->getNbRow());}
......
...@@ -426,8 +426,8 @@ namespace Faust ...@@ -426,8 +426,8 @@ namespace Faust
} }
else else
{ // storage size is the main criterion { // storage size is the main criterion
sparse_weight = fac->getNonZeros()*(sizeof(FPP)+sizeof(int))+(fac->getNbRow()+1)*sizeof(int); sparse_weight = fac->getNBytes();
if(sparse_weight < fac->getNbCol()*fac->getNbRow()*sizeof(FPP)) if(sparse_weight < fac->getNBytes())
{ {
// choose CSR format // choose CSR format
if(dfac) if(dfac)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment