I am trying to use the CUSP library. I am reading .txt files which are basically sparse COO representation. I am using CUSP to convert into CSR format.
When I print the matrix with cusp::print()
it prints the correct outcome for COO representation. However when I convert the matrix into CSR, I have written my own function for printing but the outcome is not what I want.
Here is the snippet
main()
{
//.
//bla bla
//..
//create a 2d coo matrix
cusp::coo_matrix<int, int, cusp::host_memory> D(nRows_data, nCols_data, nnz_data);
// Load data from file into sparse matrices
//fill 2D coo matrix
fill2DCooMatrixFromFile( fNameData, D );
std::cout<<"\n----------------------------\n";
cusp::print( D );
cusp::csr_matrix<int, int, cusp::host_memory> csrD = D;
std::cout<<"\n----------------------------\n";
printCSRMatrix( csrD );
}
//print csr matrix
void printCSRMatrix( cusp::csr_matrix<int, int, cusp::host_memory> csr )
{
std::cout<<"csr matrix <"<<csr.num_rows<<", "<<csr.num_cols<<"> with <csr.num_entries<<" enteries\n";
std::cout<<"V :: ";
for( int i=0 ; i<csr.values.size() ; i++ )
std::cout<<csr.values[i]<<" ";
std::cout<<"\n";
std::cout<<"CI :: ";
for( in
t i=0 ; i<csr.column_indices.size() ; i++ )
std::cout<<csr.column_indices[i]<<" ";
std::cout<<"\n";
std::cout<<"RO :: ";
for( int i=0 ; i<csr.row_offsets.size() ; i++ )
std::cout<<csr.row_offsets[i]<<" ";
std::cout<<"\n";
}
Assume that fill2DCooMatrixFromFile fills in the following matrix
1 0 1 0 0
0 0 0 1 0
0 0 0 0 0
0 1 0 0 0
0 0 0 1 0
Following is the output I get with the code
sparse matrix <5, 5> with 5 entries
0 0 1
0 2 1
1 3 1
3 1 1
4 3 1
----------------------------
csr matrix <5, 5> with 5 enteries
V :: 1 1 1 1 1
CI :: 0 2 3 1 3
RO :: 0 2 3 3 4 5
I am not able to understand the RowOffset that is the output.