SuperSCS  1.3.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Sparse Matrices

Table of Contents

CSC format

Sparse matrix in C are formated in the compressed sparse column format.

Let \(A\in\mathbb{R}^{m\times n}\) be a sparse matrix with \(q\) nonzero elements.

The compressed sparse column, henceforth CSC, representation of \(A\) is the triplet \((a, I, J)\) where

Let us give a comprehensive example...

Consider the following sparse matrix

\begin{eqnarray*} A &=& \begin{bmatrix} 0.3\\ & 0.7\\ && 0.2\\ -0.5 & 0.9 \end{bmatrix} \end{eqnarray*}

We shall derive the CSC representation of \(A\).

We have \(m=4\), \(n=3\) and we count \(q=5\) nonzero elements.

Traversing \(A\) in column-major order, we have \(a = (0.3, -0.5, 0.7, 0.9, 0.2)\).

\(I\) is an array of length \(n+1=4\); it is constructed recursively as follows:

Note that the last element of \(I\) is the number of nonzero elements of the original matrix.

Lastly, \(J\) is constructed as follows:

Exporting to CSC in MATLAB

In MATLAB, you may compute the CSC representation of a matrix A as follows:

[I,~,a] = find(sparse(A)); I = I - 1;
J = [0 cumsum(full(sum(A~=0)))];

For convenience, SuperSCS implements the MATLAB function sparse_to_csc with which you may convert a sparse matrix into its CSC format.

The function signature is:

[m, n, nnz, a, I, J] = sparse_to_csc(A);

Note that you first need to run make_scs (see the installation page).

Here is an example of use:

A = [0.3 0 0 ; 0 0.7 0; 0 0 0.2; -0.5 0.9 0];
A = sparse(A);
[m, n, nnz, a, I, J] = sparse_to_csc(A);

This will return:

m = 4
n = 3
nnz = 5
a =
0.3000
-0.5000
0.7000
0.9000
0.2000
I =
0
2
4
5
J =
0
3
1
3
2
See Also
Saving and Loading Problems