Mentions légales du service

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

Add MatDiag::get_rows() (for getting contiguous rows).

Fixing also an issue in MatSparse(MatDiag) ctor.
parent 71d30c58
No related branches found
No related tags found
No related merge requests found
...@@ -83,6 +83,9 @@ int main() ...@@ -83,6 +83,9 @@ int main()
cout << "getcols(2,5)" << endl; cout << "getcols(2,5)" << endl;
MatGeneric<FPP,Cpu>* cols = diagMat.get_cols(2,5); MatGeneric<FPP,Cpu>* cols = diagMat.get_cols(2,5);
display_all_elts(*dynamic_cast<MatDiag<FPP>*>(cols)); display_all_elts(*dynamic_cast<MatDiag<FPP>*>(cols));
cout << "getrows(2,5)" << endl;
MatGeneric<FPP,Cpu>* rows = diagMat.get_rows(2,5);
display_all_elts(*dynamic_cast<MatDiag<FPP>*>(rows));
cout << "end of test_MatDiag" << endl; cout << "end of test_MatDiag" << endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
...@@ -143,9 +143,23 @@ MatGeneric<FPP,Cpu>* MatDiag<FPP>::get_cols(faust_unsigned_int col_id_start, fau ...@@ -143,9 +143,23 @@ MatGeneric<FPP,Cpu>* MatDiag<FPP>::get_cols(faust_unsigned_int col_id_start, fau
template<typename FPP> template<typename FPP>
MatGeneric<FPP,Cpu>* MatDiag<FPP>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const MatGeneric<FPP,Cpu>* MatDiag<FPP>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const
{ {
//TODO if(num_rows+row_id_start>=this->getNbRow())
return nullptr; handleError("Matdiag", "row index is out of dimension size.");
faust_unsigned_int dmin = min(this->getNbRow(), this->getNbCol());
FPP * data = new FPP[num_rows];
if(row_id_start > dmin)
memset(data, 0, sizeof(FPP)*num_rows);
else {
if(row_id_start+num_rows > dmin)
{
faust_unsigned_int overflow = row_id_start+num_rows-dmin;
memset(data+num_rows-overflow, 0, sizeof(FPP)*overflow);
}
memcpy(data, getData()+row_id_start, num_rows*sizeof(FPP));
}
MatDiag<FPP> * ret = new MatDiag<FPP>(num_rows, this->getNbCol(), data);
delete[] data;
return ret;
} }
template<typename FPP> template<typename FPP>
......
...@@ -98,8 +98,8 @@ Faust::MatSparse<FPP,Cpu>::MatSparse(const Faust::MatDiag<FPP>& D) : Faust::MatG ...@@ -98,8 +98,8 @@ Faust::MatSparse<FPP,Cpu>::MatSparse(const Faust::MatDiag<FPP>& D) : Faust::MatG
FPP c; FPP c;
int j = 0; int j = 0;
col_ptr[0] = 0; col_ptr[0] = 0;
for(int i=0; i < min(this->dim1, this->dim2); i++) for(int i=0; i < D.getNbCol(); i++)
if((c = D.getData()[i]) != FPP(0)) if(i < nnz && (c = D.getData()[i]) != FPP(0))
{ {
id_row[j] = i; id_row[j] = i;
data[j] = c; data[j] = c;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment