Mentions légales du service

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

Fix MatBSR::operator(int,int).

It must return a reference and not a copy.
bm and bn were swapped.
parent 79065943
Branches
Tags
No related merge requests found
...@@ -149,7 +149,7 @@ class BSRMat ...@@ -149,7 +149,7 @@ class BSRMat
/** /**
* Returns the (i,j) entry of this. * Returns the (i,j) entry of this.
*/ */
T operator()(unsigned int i, unsigned int j) const; const T& operator()(unsigned int i, unsigned int j) const;
/** /**
* Returns the indices on the nonzeros of this. * Returns the indices on the nonzeros of this.
*/ */
......
...@@ -837,17 +837,17 @@ bool BSRMat<T, BlockStorageOrder>::contains_nan() const ...@@ -837,17 +837,17 @@ bool BSRMat<T, BlockStorageOrder>::contains_nan() const
} }
template<typename T, int BlockStorageOrder> template<typename T, int BlockStorageOrder>
T BSRMat<T, BlockStorageOrder>::operator()(unsigned int i, unsigned int j) const const T& BSRMat<T, BlockStorageOrder>::operator()(unsigned int i, unsigned int j) const
{ {
if(i < m && j < n) if(i < m && j < n)
{ {
// determine if (i,j) is inside a nz block // determine if (i,j) is inside a nz block
unsigned int bi = i / bn; // the block row index of (i,j) unsigned int bi = i / bm; // the block row index of (i,j)
// how many nz blocks in bi-th row // how many nz blocks in bi-th row
unsigned int bc = browptr[bi+1] - browptr[bi]; unsigned int bc = browptr[bi+1] - browptr[bi];
if(!bc) return 0; // no nz blocks in the bi-th row if(!bc) return 0; // no nz blocks in the bi-th row
// is j located in a nz block of bi-th row? // is j located in a nz block of bi-th row?
unsigned int bj = j / bm; // block column index of (i,j) unsigned int bj = j / bn; // block column index of (i,j)
for(int k=browptr[bi];k<browptr[bi+1]; k++) for(int k=browptr[bi];k<browptr[bi+1]; k++)
{ {
if(bcolinds[k] == bj) if(bcolinds[k] == bj)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment