Mentions légales du service

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

Add new get_rows function overloads (refactoring others) in MatDense and...

Add new get_rows function overloads (refactoring others) in MatDense and normInf in MatDense and MatSparse.
parent 327efe40
No related branches found
No related tags found
No related merge requests found
......@@ -384,6 +384,8 @@ namespace Faust
void real();
Real<FPP> normL1(const bool transpose=false) const;
Real<FPP> normL1(faust_unsigned_int&, const bool transpose=false) const;
Real<FPP> normInf(const bool transpose=false) const;
Real<FPP> normInf(faust_unsigned_int&, const bool transpose=false) const;
Vect<FPP,Cpu> get_col(faust_unsigned_int id) const;
Vect<FPP,Cpu> get_row(faust_unsigned_int id) const;
MatDense<FPP,Cpu>* get_cols(faust_unsigned_int start_col_id, faust_unsigned_int num_cols) const;
......@@ -401,6 +403,8 @@ namespace Faust
void delete_row(int offset);
MatDense<FPP,Cpu>* get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows) const;
void get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows, MatDense<FPP, Cpu>& out_rows) const;
void get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int n, MatDense<FPP, Cpu>& out_rows) const;
MatDense<FPP,Cpu>* get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int n) const;
MatDense<FPP,Cpu> get_block(faust_unsigned_int i, faust_unsigned_int j, faust_unsigned_int nrows, faust_unsigned_int ncols);
......
......@@ -955,7 +955,7 @@ void MatDense<FPP,Cpu>::multiplyLeft(const MatSparse<FPP,Cpu>& S,const char Tran
else
{
if (TransS == 'N')
if (TransS == 'N')
mat = S.mat * mat;
else
mat = S.mat.transpose() * mat;
......@@ -1094,6 +1094,18 @@ Real<FPP> MatDense<FPP, Cpu>::normL1(const bool transpose /* default false */) c
return normL1(id, transpose);
}
template<typename FPP>
Real<FPP> Faust::MatDense<FPP, Cpu>::normInf(const bool transpose/*=false*/) const
{
return normL1(!transpose);
}
template<typename FPP>
Real<FPP> Faust::MatDense<FPP, Cpu>::normInf(faust_unsigned_int& row_id, const bool transpose/*=false*/) const
{
return normL1(row_id, !transpose);
}
template<typename FPP>
void MatDense<FPP,Cpu>::normalize()
{
......@@ -1203,55 +1215,63 @@ template<typename FPP>
MatDense<FPP,Cpu>* MatDense<FPP,Cpu>::get_cols(std::vector<int> col_ids) const
{
int n = col_ids.size();
FPP *data = new FPP[this->getNbRow()*n];
MatDense<FPP, Cpu>* cols = new MatDense<FPP, Cpu>(this->getNbRow(), n);
FPP *data = cols.getData();
int i = 0;
for(auto j: col_ids)
{
if(j >= this->getNbCol() || j < 0)
{
delete[] data;
throw std::runtime_error("Index out of column range.");
}
memcpy(data+i*this->getNbRow(), getData()+j*this->getNbRow(), this->getNbRow()*sizeof(FPP));
i++;
}
MatDense<FPP, Cpu>* cols = new MatDense<FPP, Cpu>(data, this->getNbRow(), n);
delete[] data;
return cols;
}
template<typename FPP>
MatDense<FPP,Cpu>* MatDense<FPP,Cpu>::get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows) const
{
MatDense<FPP, Cpu>* rows = new MatDense<FPP, Cpu>(num_rows, this->getNbCol());
get_rows(start_row_id, num_rows, *rows);
return rows;
}
template<typename FPP>
void MatDense<FPP,Cpu>::get_rows(faust_unsigned_int start_row_id, faust_unsigned_int num_rows, MatDense<FPP, Cpu>& out_rows) const
{
if(start_row_id >= this->getNbRow() || start_row_id+num_rows > this->getNbRow())
throw std::domain_error("get_rows: arguments out of row indices.");
FPP *data = new FPP[this->getNbCol()*num_rows];
out_rows.resize(num_rows, this->getNbCol());
FPP *data = out_rows.getData();
for(faust_unsigned_int i = 0; i < this->getNbCol(); i++)
memcpy(data+i*num_rows, getData()+start_row_id+i*this->getNbRow(), num_rows*sizeof(FPP));
MatDense<FPP, Cpu>* rows = new MatDense<FPP, Cpu>(data, num_rows, this->getNbCol());
delete[] data;
return rows;
}
template<typename FPP>
MatDense<FPP,Cpu>* MatDense<FPP,Cpu>::get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int n) const
{
FPP *data = new FPP[this->getNbCol()*n];
MatDense<FPP, Cpu>* rows = new MatDense<FPP, Cpu>(n, this->getNbCol());
this->get_rows(row_ids, n, *rows);
return rows;
}
template<typename FPP>
void MatDense<FPP,Cpu>::get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int n, MatDense<FPP, Cpu>& out_rows) const
{
out_rows.resize(n, this->getNbCol());
FPP *data = out_rows.getData();
for(faust_unsigned_int i = 0; i < n; i++) // row_ids[i]
for(faust_unsigned_int j = 0; j < this->getNbCol(); j++)
{
if(row_ids[i] >= this->getNbRow())
{
delete[] data;
throw std::runtime_error("Index out of row range.");
}
//copy ele row_ids[i],j
data[j*n+i] = this->mat(row_ids[i],j);
}
MatDense<FPP, Cpu>* rows = new MatDense<FPP, Cpu>(data, n, this->getNbCol());
delete [] data;
return rows;
}
template<typename FPP>
bool MatDense<FPP,Cpu>::eq_cols(const MatDense<FPP, Cpu> & other, faust_unsigned_int id_this, faust_unsigned_int id_other, const Real<FPP>& precision) const
{
......
......@@ -348,6 +348,9 @@ namespace Faust
matvar_t* toMatIOVarDense(bool transpose, bool conjugate) const;
Real<FPP> normL1(const bool transpose=false) const;
Real<FPP> normL1(faust_unsigned_int&, const bool transpose=false) const;
Real<FPP> normInf(const bool transpose=false) const;
Real<FPP> normInf(faust_unsigned_int&, const bool transpose=false) const;
const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const{return const_cast<Eigen::SparseMatrix<FPP,Eigen::RowMajor>*>(&mat)->coeffRef(i,j);}
Vect<FPP,Cpu> get_col(faust_unsigned_int id) const;
......
......@@ -883,6 +883,18 @@ Real<FPP> Faust::MatSparse<FPP, Cpu>::normL1(const bool transpose /* default fal
return normL1(id,transpose);
}
template<typename FPP>
Real<FPP> Faust::MatSparse<FPP, Cpu>::normInf(const bool transpose/*=false*/) const
{
return normL1(!transpose);
}
template<typename FPP>
Real<FPP> Faust::MatSparse<FPP, Cpu>::normInf(faust_unsigned_int& row_id, const bool transpose/*=false*/) const
{
return normL1(row_id, !transpose);
}
template<typename FPP>
Faust::Vect<FPP,Cpu> Faust::MatSparse<FPP,Cpu>::get_col(faust_unsigned_int id) const
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment