SMG2S
Sparse Matrix Generator with Given Spectrum
|
|
24 #ifndef __MATRIXCSR_H__
25 #define __MATRIXCSR_H__
45 template<
typename T,
typename S>
102 rows.reserve(nrows_in+1);
113 MatrixCSR(std::vector<S> rowoffs, std::vector<S> colidxs, std::vector<T> values)
116 nnz = colidxs.size();
117 ncols = rowoffs.size() - 1;
118 nrows = rowoffs.size() - 1;
145 for(S pos =
rows[row - 1] - 1; pos <
rows[row] - 1; ++pos){
167 for(S pos =
rows[row - 1] - 1; pos <
rows[row] - 1; ++pos){
185 typename std::vector<S>::iterator it=
cols.begin();
186 typename std::vector<T>::iterator itv=
vals.begin();
188 for(S pos =
rows[row - 1] - 1; pos <
rows[row] - 1; ++pos){
190 prevCol =
cols[pos-1];
193 }
else if((currCol > col) && (prevCol < col)){
194 std::advance(it,currCol);
195 std::advance(itv,currCol);
197 vals.insert(itv, val);
209 std::cout <<
"MatrixCSR display:" << std::endl;
210 for(
auto i = 0; i <
rows.size() - 1; i++){
211 for(
auto j =
rows[i]; j <
rows[i+1]; j++){
212 std::cout <<
"row " << i <<
": (" <<
cols[j] <<
"," <<
vals[j]<<
")";
214 std::cout << std::endl;
std::vector< T > vals
An array stores the values of non-zero elements.
Definition: MatrixCSR.hpp:86
S ncols
dimension of the array MatrixCSR::cols
Definition: MatrixCSR.hpp:64
MatrixCSR(std::vector< S > rowoffs, std::vector< S > colidxs, std::vector< T > values)
A constructor of `MatrixCSR`. The three arrays MatrixCSR::rows, MatrixCSR::cols and MatrixCSR::vals a...
Definition: MatrixCSR.hpp:113
std::vector< S > rows
An array points to row starts in indices and data.
Definition: MatrixCSR.hpp:72
~MatrixCSR()
This a destructor of MatrixCSR.
Definition: MatrixCSR.hpp:126
void InsertValue(S row, S col, T val)
Insert a value `val` in the position `(row, col)` in sparse matrix.
Definition: MatrixCSR.hpp:182
A struct which stores a sparse matrix in CSR format.
Definition: MatrixCSR.hpp:46
S nnz
number of non-zero entries of a sparse matrix
Definition: MatrixCSR.hpp:57
MatrixCSR(S nnz_in, S nrows_in)
A constructor of `MatrixCSR`. The three arrays MatrixCSR::rows, MatrixCSR::cols and MatrixCSR::vals a...
Definition: MatrixCSR.hpp:95
void show()
Print the sparse matrix in COO format.
Definition: MatrixCSR.hpp:208
T GetValue(S row, S col)
Get the value of position `(row, col)` from sparse matrix.
Definition: MatrixCSR.hpp:140
std::vector< S > cols
An array stores the column indices of non-zero elements.
Definition: MatrixCSR.hpp:79
S nrows
number of rows of a sparse matrix
Definition: MatrixCSR.hpp:52
void SetValue(S row, S col, T val)
Overwrite the value of entry of position `(row, col)` in sparse matrix by `val`.
Definition: MatrixCSR.hpp:163