qpOASES
qpOASES copied to clipboard
What do the arguments mean of SymSparseMat class?
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.cpp
、 qrecipe_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!
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.