Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What do the arguments mean of SymSparseMat class? #105

Open
AlBrP opened this issue Sep 23, 2020 · 1 comment
Open

What do the arguments mean of SymSparseMat class? #105

AlBrP opened this issue Sep 23, 2020 · 1 comment

Comments

@AlBrP
Copy link

AlBrP commented Sep 23, 2020

Hi, I want to create symmetric sparse matrix by SymSparseMat class so I check the Matrices.hpp for arguments descriptions.

int_t nr,           /**< Number of rows. */
int_t nc,           /**< Number of columns. */
sparse_int_t* r,    /**< Row indices (length). */
sparse_int_t* c,    /**< Indices to first entry of columns (nCols+1). */
real_t* v           /**< Vector of entries (length). */

I don't understand these three agruments: sparse_int_t* r sparse_int_t* c real_t* v.

Before creating this issue, I have saw the qrecipe.cppqrecipe_data.hpp but I still can not understand whar the arguments mean. I also googled for answers about this question but I couldn't find simliar questions.

Could you please give me a simple example(like creating a 3*3 symmetric sparse matrix ) to explain what these three arguments mean?

Thanks a lot in advance!

@jhallier
Copy link

jhallier commented Apr 7, 2021

Hi,
I had the same question, and eventually figured that the matrix is in a column-compressed storage format. There's a good example here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc_matrix.html or here https://de.wikipedia.org/wiki/Harwell-Boeing-Format (only in German, the English version doesn't have the example).

So basically, you go through your matrix column-wise, then add each non-zero value to v and each row of that entry to r, and in c you save the position of the first element in v for each column, plus one past the last element (equaling the total number of entries) - length of c is (number of columns + 1).

Example:
0 3 4 0
1 0 0 0
0 0 1 0
1 0 0 0
v = { 1, 1, 3, 4, 1}
r = { 1, 3, 0, 0, 2}
c = {0, 2, 3, 3, 5}

Should this be added to the documentation? It may help to understand how to fill the sparse matrices.

Also note that after creating a SymSparseMat, other than a SparseMatrix, you need to call the method createDiagInfo() afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants