CSC Format for Sparse Matrices
- CSC Format is a sparse matrix representation using three arrays (val, rowidx, colptr) that enable efficient column-oriented access and traversal.
- Extensions such as VCSC and IVCSC leverage redundancy in column data to reduce memory usage significantly, with reductions up to 7.5× in high-redundancy scenarios.
- CSC supports fast operations like SpMV with O(nnz) time complexity, balancing storage requirements with computational performance in scientific and numerical applications.
The Compressed Sparse Column (CSC) format is a canonical data structure for representing sparse matrices in memory, particularly designed to optimize storage efficiency and computational performance for column-oriented access patterns. Widely adopted in numerical linear algebra and scientific computing, CSC is foundational for high-performance sparse matrix-vector and matrix-matrix operations. Extensions of CSC, such as Value-Compressed Sparse Column (VCSC) and Index- and Value-Compressed Sparse Column (IVCSC), have been developed to address scenarios with additional data redundancy, relevant in domains like genomics and recommender systems (Ruiter et al., 2023).
1. CSC Format: Structure and Semantics
CSC encodes a sparse matrix with nonzero elements using three contiguous arrays:
- : the nonzero values, stored column-wise.
- : the corresponding row indices for each value.
- : a pointer array marking the boundaries of each column in and , where is the start index in column and (Ruiter et al., 2023).
Example:
Given
with , CSC arrays are:
This structure enables efficient traversal and access for operations (e.g., SpMV) and balances storage needs and random-access efficiency.
2. Storage Analysis and Memory Footprint
Memory usage in CSC is determined by the data types used to represent matrix entries and indices:
where is the byte size per value (e.g., 8 bytes for double), and is the byte size per index (e.g., 4 bytes for 32-bit integer) (Ruiter et al., 2023).
The first two terms account for storage of nonzero values and their indices, while the final term encodes the column pointers. Compared with the Coordinate (COO) format, which uses , CSC reduces storage overhead by omitting explicit storage of column indices per nonzero.
3. Computational Operations and Complexity
CSC is optimized for column-access patterns, particularly efficient for:
Iteration proceeds column-by-column.
1 2 3 |
for j in range(n): for k in range(colptr[j], colptr[j+1]): y[rowidx[k]] += val[k] * x[j] |
- Element Lookup :
Requires scanning in for , yielding per lookup, where is the count of nonzeros in column .
4. Extensions: VCSC and IVCSC
Conventional CSC captures only sparsity, not redundancy in the value distribution within matrix columns. Two recent extensions have addressed this limitation (Ruiter et al., 2023):
- Value-Compressed Sparse Column (VCSC):
- : unique nonzero values.
- : occurrence counts for each unique value.
- : row indices partitioned by value group.
- Offsets to flatten arrays.
The memory usage is:
where is the count of unique values in column . When redundancy is large, this achieves substantial compression.
- Index- and Value-Compressed Sparse Column (IVCSC):
- Positive deltas are stored using the minimal possible byte-width.
- Groups are prefixed with a per-group byte width, minimizing index storage to the theoretical minimum, especially when deltas are small.
In practice, IVCSC reaches up to memory reduction over CSC in redundancy-dominated matrices (e.g., genomics data, mean redundancy ratio MMR ) (Ruiter et al., 2023).
5. Compression Ratios and Empirical Results
Compression capability of CSC, VCSC, and IVCSC formats is strongly influenced by the redundancy of nonzero values:
- In high-redundancy regimes (column-wise repeated values), VCSC reduces memory usage by up to vs. CSC, IVCSC by up to .
- On a nonzero single-cell genomics matrix (MMR $0.987$), memory usage as a percentage of the uncompressed COO size was: CSC , VCSC , IVCSC .
- When redundancy is low (e.g., unique floats per entry), VCSC and IVCSC offer no benefit and may increase memory usage (Ruiter et al., 2023).
| Dataset | Sparsity | MMR | CSC (%) | VCSC (%) | IVCSC (%) | |
|---|---|---|---|---|---|---|
| Single-cell | 91.9% | 0.987 | 75 | 26 | 9 | |
| MovieLens | 97.0% | 0.616 | 76 | 33 | 18 | |
| Simulated unique | 90.0% | 0.0 | 75 | 100 | 105 |
A plausible implication is that the choice of format should be matched to the data’s redundancy profile.
6. Performance Trade-Offs and Applicability
- CSC/COO: Offer the fastest SpMV and SpMM, with storage. Construction from COO is fastest when redundancy is low.
- VCSC: Incurs per-column looping overhead and offers its largest gains when . In benchmarked ML/genomics workloads, SpMV is within of CSC's runtime.
- IVCSC: Maximizes memory savings—up to vs. COO, vs. CSC—at the cost of slower SpMV (e.g., 420 ms for IVCSC vs. 140 ms for CSC in a matrix with 90% mean redundancy). Construction time remains tractable ( ms on matrices at low redundancy).
Selection guidelines for practitioners:
- Use CSC/COO for general sparse data with little redundancy.
- Use VCSC when columns aggregate repeated values (count data, ratings, genomics); minor performance cost, significant memory reduction.
- Use IVCSC where memory capacity is limiting and reduced I/O bandwidth or slower decompression can be tolerated (e.g., offline post-processing of very large matrices) (Ruiter et al., 2023).
7. Contextual Relevance and Limitations
CSC remains a preferred default for a broad spectrum of sparse linear algebra workloads due to low overhead and compatibility with major computing frameworks. However, its inability to exploit nonzero value redundancy has motivated the creation of VCSC and IVCSC, particularly for modern data modalities with structured repetition. The effectiveness of these extensions is empirically bounded by the actual redundancy and local row-index proximity in the data. Deployment of VCSC and IVCSC should explicitly consider their overheads in construction time, per-column uniqueness ratio, and compatibility with existing computational routines—factors that delimit their applicability for certain classes of problems (Ruiter et al., 2023).