Mentions légales du service

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

Update MatBSR: new ctor, get_cols/rows signature fix (id type), new to_sparse function.

parent 8377d375
Branches
Tags
No related merge requests found
......@@ -37,6 +37,7 @@ namespace Faust
MatBSR() : MatGeneric<FPP, Cpu>() {}
MatBSR(BSRMat<FPP>& mat);
public:
MatBSR(faust_unsigned_int nrows, faust_unsigned_int ncols, faust_unsigned_int bnrows, faust_unsigned_int bncols, faust_unsigned_int nblocks, const FPP* data, const int *block_rowptr, const int* block_colinds);
MatGeneric<FPP,Cpu>* Clone(const bool isOptimize=false) const;
void multiply(Vect<FPP,Cpu> & vec, char opThis) const;
Vect<FPP,Cpu> multiply(const Vect<FPP,Cpu> &v) const; // from LinearOperator
......@@ -58,19 +59,24 @@ namespace Faust
Real<FPP> norm() const;
Real<FPP> normL1(faust_unsigned_int& col_id, const bool transpose) const;
Vect<FPP,Cpu> get_col(faust_unsigned_int id) const;
MatGeneric<FPP,Cpu>* get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const;
MatGeneric<FPP,Cpu>* get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const;
MatGeneric<FPP,Cpu>* get_cols(const faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
MatGeneric<FPP,Cpu>* get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const;
MatSparse<FPP,Cpu>* get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const;
MatSparse<FPP,Cpu>* get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const;
MatSparse<FPP,Cpu>* get_cols(const faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const;
MatSparse<FPP,Cpu>* get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const;
std::list<std::pair<int,int>> nonzeros_indices() const;
void setZeros();
bool containsNaN();
bool containsNaN() const;
const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const ;
MatDense<FPP, Cpu> to_dense() const;
MatSparse<FPP, Cpu> to_sparse() const;
/**
* Returns the number of nonzeros blocks.
*/
size_t getNBlocks() const;
/**
* Returns the number of blocks along the dim_id dimension.
* \param dim_id 0 for row dimension, 1 for column dimension.
*/
size_t getNbBlocksPerDim(int dim_id) const;
/**
* Returns number of rows of each nonzero block.
......@@ -116,6 +122,7 @@ class BSRMat
// private default constructor
BSRMat(): data(nullptr), bcolinds(nullptr), browptr(nullptr), bnnz(0), m(0), n(0), bm(0), bn(0), b_per_rowdim(0), b_per_coldim(0) {}
public:
BSRMat(unsigned long int nrows, unsigned long int ncols, unsigned long int bnrows, unsigned long int bncols, unsigned long int nblocks, const T* data, const int *block_rowptr, const int *block_colinds);
/** Copy constructor */
BSRMat(const BSRMat<T, BlockStorageOrder>& src_bmat);
/** Move constructor */
......
......@@ -6,6 +6,11 @@
namespace Faust
{
template<typename FPP>
MatBSR<FPP, Cpu>::MatBSR(faust_unsigned_int nrows, faust_unsigned_int ncols, faust_unsigned_int bnrows, faust_unsigned_int bncols, faust_unsigned_int nblocks, const FPP* data, const int *block_rowptr, const int *block_colinds) : MatGeneric<FPP, Cpu>(nrows, ncols), bmat(nrows, ncols, bnrows, bncols, nblocks, data, block_rowptr, block_colinds)
{
}
template <typename FPP>
MatBSR<FPP,Cpu>::MatBSR(BSRMat<FPP>& bmat)
{
......@@ -324,34 +329,38 @@ namespace Faust
}
template <typename FPP>
MatGeneric<FPP,Cpu>* MatBSR<FPP,Cpu>::get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const
MatSparse<FPP,Cpu>* MatBSR<FPP,Cpu>::get_cols(faust_unsigned_int col_id_start, faust_unsigned_int num_cols) const
{
auto smat = new MatSparse<FPP, Cpu>(this->dim1, num_cols);
smat->mat = bmat.get_rows(col_id_start, num_cols);
smat->mat = bmat.get_cols(col_id_start, num_cols);
smat->update_dim();
return smat;
}
template <typename FPP>
MatGeneric<FPP,Cpu>* MatBSR<FPP,Cpu>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const
MatSparse<FPP,Cpu>* MatBSR<FPP,Cpu>::get_rows(faust_unsigned_int row_id_start, faust_unsigned_int num_rows) const
{
auto smat = new MatSparse<FPP, Cpu>(num_rows, this->dim2);
smat->mat = bmat.get_rows(row_id_start, num_rows);
smat->update_dim();
return smat;
}
template <typename FPP>
MatGeneric<FPP,Cpu>* MatBSR<FPP,Cpu>::get_cols(const faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const
MatSparse<FPP,Cpu>* MatBSR<FPP,Cpu>::get_cols(const faust_unsigned_int* col_ids, faust_unsigned_int num_cols) const
{
auto smat = new MatSparse<FPP, Cpu>(this->dim1, num_cols);
smat->mat = bmat.get_rows(col_ids, num_cols);
smat->mat = bmat.get_cols(col_ids, num_cols);
smat->update_dim();
return smat;
}
template <typename FPP>
MatGeneric<FPP,Cpu>* MatBSR<FPP,Cpu>::get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const
MatSparse<FPP,Cpu>* MatBSR<FPP,Cpu>::get_rows(const faust_unsigned_int* row_ids, faust_unsigned_int num_rows) const
{
auto smat = new MatSparse<FPP, Cpu>(num_rows, this->dim2);
smat->mat = bmat.get_rows(row_ids, num_rows);
smat->update_dim();
return smat;
}
......@@ -370,7 +379,7 @@ namespace Faust
}
template <typename FPP>
bool MatBSR<FPP,Cpu>::containsNaN()
bool MatBSR<FPP,Cpu>::containsNaN() const
{
return bmat.contains_nan();
}
......@@ -384,11 +393,21 @@ namespace Faust
template <typename FPP>
MatDense<FPP, Cpu> MatBSR<FPP,Cpu>::to_dense()const
{
MatDense<FPP, Cpu> dmat(this->dim1, this->dim2);
MatDense<FPP, Cpu> dmat;
dmat.mat = bmat.to_dense();
dmat.dim1 = bmat.m;
dmat.dim2 = bmat.n;
return dmat;
}
template <typename FPP>
MatSparse<FPP, Cpu> MatBSR<FPP,Cpu>::to_sparse()const
{
MatSparse<FPP, Cpu> smat(this->dim1, this->dim2);
smat.mat = bmat.to_sparse();
return smat;
}
template <typename FPP>
MatBSR<FPP,Cpu>::~MatBSR()
{
......@@ -412,6 +431,33 @@ BSRMat<T, BlockStorageOrder>::BSRMat(const BSRMat<T, BlockStorageOrder>& src_bma
*this = src_bmat;
}
template<typename T, int BlockStorageOrder>
BSRMat<T, BlockStorageOrder>::BSRMat(unsigned long int nrows, unsigned long int ncols, unsigned long int bnrows, unsigned long int bncols, unsigned long int nblocks, const T* data, const int *block_rowptr, const int *block_colinds) : BSRMat<T, BlockStorageOrder>()
{
// verify bm and bn evenly divide m and n
if(nrows%bnrows)
throw std::runtime_error("BSRMat error: bnrows must evenly divide nrows.");
if(ncols%bncols)
throw std::runtime_error("BSRMat error: bncols must evenly divide ncols.");
// enforce bnnz is less or equel to m*n/bm/bn
nblocks = std::min(nblocks, nrows*ncols/bnrows/bncols);
this->m = nrows;
this->n = ncols;
this->bm = bnrows;
this->bn = bncols;
this->bnnz = nblocks;
this->b_per_rowdim = this->n/this->bn;
this->b_per_coldim = this->m/this->bm;
int data_size = bnnz*bm*bn;
// init data
this->data = new T[data_size];
memcpy(this->data, data, sizeof(T)*nblocks);
this->browptr = new int[this->b_per_coldim+1];
memcpy(this->browptr, block_rowptr, sizeof(int)*(this->b_per_rowdim+1));
this->bcolinds = new int[this->bnnz];
memcpy(this->bcolinds, block_colinds, sizeof(int)*this->bnnz);
}
template<typename T, int BlockStorageOrder>
BSRMat<T, BlockStorageOrder>::BSRMat(BSRMat<T, BlockStorageOrder>&& src_bmat) : BSRMat<T, BlockStorageOrder>()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment