Mentions légales du service

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

New member functions for MatBSR: getNBlocks, getNbBlockRow/Col, getNbBlocksPerDim + fix get_col.

parent 9967376c
Branches
Tags
No related merge requests found
...@@ -67,6 +67,19 @@ namespace Faust ...@@ -67,6 +67,19 @@ namespace Faust
bool containsNaN(); bool containsNaN();
const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const ; const FPP& operator()(faust_unsigned_int i, faust_unsigned_int j)const ;
MatDense<FPP, Cpu> to_dense() const; MatDense<FPP, Cpu> to_dense() const;
/**
* Returns the number of nonzeros blocks.
*/
size_t getNBlocks() const;
size_t getNbBlocksPerDim(int dim_id) const;
/**
* Returns number of rows of each nonzero block.
*/
size_t getNbBlockRow() const;
/**
* Returns the number of columns of each nonzero block.
*/
size_t getNbBlockCol() const;
virtual ~MatBSR(); virtual ~MatBSR();
static MatBSR<FPP, Cpu>* randMat(int m, int n, int bm, int bn, int bnnz); static MatBSR<FPP, Cpu>* randMat(int m, int n, int bm, int bn, int bnnz);
}; };
...@@ -82,23 +95,23 @@ class BSRMat ...@@ -82,23 +95,23 @@ class BSRMat
// \brief the data of nonzero blocks (size bnnz*bm*bn). // \brief the data of nonzero blocks (size bnnz*bm*bn).
T* data; T* data;
// \brief column indices of the nonzero blocks (size bnnz). // \brief column indices of the nonzero blocks (size bnnz).
int* bcolinds; int* bcolinds;// TODO: should be unsigned
// \brief the buffer of cumulative number of blocks per block row (size b_per_coldim+1). // \brief the buffer of cumulative number of blocks per block row (size b_per_coldim+1).
int* browptr; int* browptr;// TODO: should be unsigned
// \brief the number of nonzero blocks. // \brief the number of nonzero blocks
int bnnz; int bnnz;// TODO: should be unsigned
// \brief the number of matrix rows. // \brief the number of matrix rows.
int m; int m; // TODO: should be unsigned
// \brief the number of matrix columns. // \brief the number of matrix columns.
int n; int n;// TODO: should be unsigned
// \brief the number of block rows. // \brief the number of block rows.
int bm; int bm;// TODO: should be unsigned
// \brief the number of block columns. // \brief the number of block columns.
int bn; int bn;// TODO: should be unsigned
// \brief the number of blocks along the row dimension of the matrix (m/bm). // \brief the number of blocks along the row dimension of the matrix (m/bm).
int b_per_rowdim; int b_per_rowdim;// TODO: should be unsigned
// \brief the number of blocks along the column dimension of the matrix (n/bn). // \brief the number of blocks along the column dimension of the matrix (n/bn).
int b_per_coldim; int b_per_coldim;// TODO: should be unsigned
// private default constructor // 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) {} 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) {}
......
...@@ -185,6 +185,8 @@ namespace Faust ...@@ -185,6 +185,8 @@ namespace Faust
void MatBSR<FPP,Cpu>::transpose() void MatBSR<FPP,Cpu>::transpose()
{ {
bmat.transpose(/*inplace*/ true); bmat.transpose(/*inplace*/ true);
this->dim1 = bmat.m;
this->dim2 = bmat.n;
} }
template <typename FPP> template <typename FPP>
...@@ -213,6 +215,38 @@ namespace Faust ...@@ -213,6 +215,38 @@ namespace Faust
return bmat.nbytes(); return bmat.nbytes();
} }
template <typename FPP>
size_t MatBSR<FPP,Cpu>::getNbBlockRow()const
{
return bmat.bm;
}
template <typename FPP>
size_t MatBSR<FPP,Cpu>::getNbBlockCol()const
{
return bmat.bn;
}
template <typename FPP>
size_t MatBSR<FPP,Cpu>::getNbBlocksPerDim(int dim_id) const
{
switch(dim_id)
{
case 0:
return bmat.b_per_rowdim;
case 1:
return bmat.b_per_coldim;
default:
throw std::runtime_error("MatBSR::getNbBlocksPerDim invalid dimension id (must be 0 or 1).");
}
}
template <typename FPP>
size_t MatBSR<FPP,Cpu>::getNBlocks() const
{
return bmat.bnnz;
}
template <typename FPP> template <typename FPP>
MatType MatBSR<FPP,Cpu>::getType() const MatType MatBSR<FPP,Cpu>::getType() const
{ {
...@@ -286,6 +320,7 @@ namespace Faust ...@@ -286,6 +320,7 @@ namespace Faust
{ {
Vect<FPP, Cpu> v(this->dim1); Vect<FPP, Cpu> v(this->dim1);
v.vec = bmat.get_col(id); v.vec = bmat.get_col(id);
return v;
} }
template <typename FPP> template <typename FPP>
...@@ -514,7 +549,7 @@ void BSRMat<T,BlockStorageOrder>::print_bufs() ...@@ -514,7 +549,7 @@ void BSRMat<T,BlockStorageOrder>::print_bufs()
template<typename T, int BlockStorageOrder> DenseMat<T> BSRMat<T, BlockStorageOrder>::to_dense() const template<typename T, int BlockStorageOrder> DenseMat<T> BSRMat<T, BlockStorageOrder>::to_dense() const
{ {
DenseMat<T> dmat(this->m, this->n); DenseMat<T> dmat = DenseMat<T>::Zero(this->m, this->n);
iter_block([&dmat, this](int mat_row_id, int mat_col_id, int block_offset) iter_block([&dmat, this](int mat_row_id, int mat_col_id, int block_offset)
{ {
dmat.block(mat_row_id, mat_col_id, bm, bn) = DenseMatMap<T>(data+block_offset*bm*bn, bm, bn); dmat.block(mat_row_id, mat_col_id, bm, bn) = DenseMatMap<T>(data+block_offset*bm*bn, bm, bn);
...@@ -708,8 +743,6 @@ BSRMat<T, BlockStorageOrder> BSRMat<T, BlockStorageOrder>::transpose(const bool ...@@ -708,8 +743,6 @@ BSRMat<T, BlockStorageOrder> BSRMat<T, BlockStorageOrder>::transpose(const bool
for(int i=1;i<b_per_rowdim+1;i++) for(int i=1;i<b_per_rowdim+1;i++)
browptr[i] += browptr[i-1]; browptr[i] += browptr[i-1];
free_bufs(); free_bufs();
this->m = m;
this->n = n;
this->bm = bm; this->bm = bm;
this->bn = bn; this->bn = bn;
this->b_per_rowdim = b_per_rowdim; this->b_per_rowdim = b_per_rowdim;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment