Mentions légales du service

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

Add/implement nonzero_indices() in the whole MatGeneric class hierarchy.

parent 0e58cde7
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,7 @@ namespace Faust
MatGeneric<FPP,Cpu>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
MatGeneric<FPP,Cpu>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const;
const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const{if(i == j) return getData()[i]; return 0;}
list<pair<int,int>> nonzeros_indices() const;
//! \brief Returns all the features of the MatDense.
std::string to_string(const bool transpose=false, const bool displaying_small_mat_elts=false) const;
void Display() const;
......
......@@ -173,4 +173,12 @@ MatGeneric<FPP,Cpu>* MatDiag<FPP>::get_rows(faust_unsigned_int* row_ids, faust_u
{
return MatSparse<FPP,Cpu>(*this).get_rows(row_ids, num_rows);
}
template<typename FPP>
list<pair<int,int>> MatDiag<FPP>::nonzeros_indices() const
{
list<pair<int,int>> nz_inds;
for(int i=0;i<this->getNbRow();i++)
nz_inds.push_back(make_pair(i,i));
return nz_inds;
}
......@@ -304,10 +304,14 @@ 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;
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
static MatSparse<FPP, Cpu>* randMat(faust_unsigned_int num_rows, faust_unsigned_int num_cols, double density, bool per_row);
static MatSparse<FPP, Cpu>* eye(faust_unsigned_int num_rows, faust_unsigned_int num_cols);
//! Destructor
~MatSparse(){/*std::cout<<"destructor MatSparse"<<std::endl;*//*this->mat.resize(0,0);*/}
......
......@@ -260,7 +260,7 @@ void Faust::MatSparse<FPP,Cpu>::multiply(Faust::MatSparse<FPP,Cpu> & M, char opT
}
template<typename FPP>
void Faust::MatSparse<FPP,Cpu>::multiplyRight(Faust::MatSparse<FPP,Cpu> const& M)
void Faust::MatSparse<FPP,Cpu>::multiplyRight(Faust::MatSparse<FPP,Cpu> const & M)
{
this->mat = this->mat*M.mat;
this->update_dim();
......@@ -1010,5 +1010,28 @@ Faust::MatSparse<FPP, Cpu>* Faust::MatSparse<FPP, Cpu>::eye(faust_unsigned_int n
return eye;
}
template<typename FPP>
list<pair<int,int>> Faust::MatSparse<FPP,Cpu>::nonzeros_indices() const
{
list<pair<int,int>> nz_inds;
int i,j, k;
unsigned int rowi_nelts = 0;
//makeCompression(); // assuming it's already done
for(i=0;i<this->dim1;i++)
{
rowi_nelts = getOuterIndexPtr()[i+1] - getOuterIndexPtr()[i];
if(rowi_nelts)
{
//non-empty row (nonzero elements)
for(k=getOuterIndexPtr()[i];k<getOuterIndexPtr()[i+1];k++)
{
j = getInnerIndexPtr()[k];
nz_inds.push_back(make_pair(i,j));
}
}
}
return nz_inds;
}
#endif
......@@ -195,7 +195,7 @@ namespace Faust
virtual Faust::MatGeneric<FPP,DEVICE>* get_cols(faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const=0;
//! \brief Returns a sub-group of rows of this matrix as the same type of matrix
virtual Faust::MatGeneric<FPP,DEVICE>* get_rows(faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const=0;
virtual list<pair<int,int>> nonzeros_indices() const=0;
void set_orthogonal(const bool is_ortho) { this->is_ortho = is_ortho; /* TODO: move def in hpp*/}
virtual const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const =0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment