Inferensys

Glossary

COO Format (Coordinate Format)

COO format is a sparse tensor storage method that explicitly stores a list of (row, column, value) tuples for each non-zero element, offering simplicity but potentially higher memory overhead.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
SPARSE MODEL INFERENCE

What is COO Format (Coordinate Format)?

COO (Coordinate Format) is a fundamental sparse tensor storage scheme that explicitly lists the coordinates and values of every non-zero element.

The COO (Coordinate Format) is a sparse tensor storage scheme that explicitly stores a list of (row, column, value) tuples for every non-zero element. It is defined by three parallel arrays: row_indices, col_indices, and values. This simple, flexible format is easy to construct and modify, making it a common intermediate representation for sparse operations. However, its memory overhead for storing explicit indices can be high, and its performance for operations like Sparse Matrix Multiplication (SpMM) is often suboptimal compared to compressed formats like CSR (Compressed Sparse Row).

For efficient sparse inference, COO's primary limitation is irregular memory access. Executing a SpMM kernel requires inefficient gather-scatter operations across the dense input matrix, leading to load imbalance and poor cache utilization. While COO is useful for incremental construction or highly irregular sparsity, production sparse inference engines typically convert it to a compressed format like CSR or a blocked sparse data layout for execution. This conversion minimizes sparse kernel overhead and better leverages hardware, such as Sparse Tensor Cores that require structured patterns like N:M sparsity.

SPARSE TENSOR REPRESENTATION

Key Characteristics of COO Format

The Coordinate (COO) format is a foundational sparse tensor storage scheme that explicitly lists the indices and values of every non-zero element. Its simplicity makes it a versatile building block, but its memory efficiency depends heavily on the operation and sparsity pattern.

01

Core Data Structure

The COO format stores a sparse tensor using three parallel arrays (or lists of tuples) of equal length:

  • Coordinates Array(s): One array per dimension (e.g., rows, cols) containing the integer indices of each non-zero element.
  • Values Array: A contiguous array containing the data value (e.g., float32) of each corresponding non-zero element. For a 2D matrix with nnz non-zeros, storage requires O(3 * nnz) memory: nnz row indices, nnz column indices, and nnz values. This explicit indexing makes construction and random element access straightforward.
02

Simplicity & Flexibility

COO's primary advantage is its conceptual and implementation simplicity. It imposes no structural constraints, making it ideal for:

  • Dynamic Construction: Easily incrementally assemble a sparse tensor by appending (index, value) tuples.
  • Irregular Sparsity: Efficiently represents completely unstructured sparsity patterns where non-zeros are randomly distributed.
  • High-Dimensional Tensors: Naturally extends to N-dimensional data by simply adding more coordinate arrays. This flexibility makes COO a common intermediate format in sparse linear algebra libraries, used for constructing matrices before conversion to more operation-optimized formats like CSR or CSC.
03

Memory & Performance Overheads

The explicit storage of all coordinates leads to significant memory overhead compared to compressed formats. For a matrix, COO uses 2 * nnz integers for indices, while CSR uses nnz + (num_rows + 1) integers. Performance bottlenecks arise from:

  • Random Access for Operations: Matrix-vector multiplication (SpMV) requires indirect, non-sequential gathers from the dense vector, causing poor cache utilization.
  • Duplicate Entries: The format allows multiple entries for the same coordinate, requiring a summation pass to coalesce duplicates, which adds preprocessing cost.
  • No Fast Row Traversal: Unlike CSR, iterating over all non-zeros in a specific row requires scanning the entire rows array, an O(nnz) operation.
04

Typical Use Cases

COO is best suited for scenarios where its construction benefits outweigh its operational inefficiencies:

  • Sparse Tensor I/O & Serialization: A simple, portable format for saving/loading sparse data (e.g., in MLX, SciPy's .npz files).
  • Graph Construction: Representing adjacency matrices for graph algorithms where edges are added incrementally.
  • Sparse Matrix Assembly in finite element analysis, where element stiffness matrices are summed into a global matrix.
  • Conversion Hub: Often used as a canonical format to convert between other sparse formats (e.g., CSR ↔ CSC) due to its symmetric treatment of dimensions.
05

Comparison to CSR Format

COO and Compressed Sparse Row (CSR) are the two most common sparse matrix formats. Their key differences are:

  • Index Storage: COO stores explicit (row, col) per element. CSR compresses row pointers, storing only col indices per element and a row_ptr array of size num_rows + 1.
  • Row-Based Operations: CSR provides O(1) access to the start of a row's data, making SpMV and row-slicing highly efficient. COO does not.
  • Construction: Building CSR directly is complex; it's often built via COO.
  • Memory: For typical matrices, CSR uses less memory than COO. COO becomes competitive only when nnz is very small or num_rows is very large.
06

Variants & Optimizations

Several optimized variants of COO address its shortcomings:

  • Sorted COO: The coordinate arrays are sorted lexicographically (e.g., by row, then column). This enables faster conversion to CSR/CSC and improves cache locality for some operations.
  • Blocked COO (BCOO): Groups non-zero values into small, dense blocks (e.g., 2x2). Stores block coordinates and a dense block values array. This reduces index storage overhead and improves arithmetic intensity for structured sparsity.
  • Compressed COO: Uses run-length encoding on one dimension (like CSR) but keeps full indices for the other, offering a middle-ground between COO and CSR. These variants illustrate the trade-off space between flexibility, memory footprint, and operational speed inherent to sparse storage.
COMPARISON

COO vs. Other Sparse Formats

A feature and performance comparison of the COO (Coordinate) format against other common sparse tensor storage formats, highlighting trade-offs in memory, access patterns, and computational efficiency.

Feature / MetricCOO (Coordinate)CSR (Compressed Sparse Row)CSC (Compressed Sparse Column)Blocked Sparse (e.g., BSR)

Primary Storage Structure

List of (row, col, value) tuples

Three arrays: row pointers, column indices, values

Three arrays: column pointers, row indices, values

Array of dense sub-blocks + block indices

Construction & Modification

Easy, O(1) insertion

Complex, requires sorting/compression

Complex, requires sorting/compression

Moderate, requires block alignment

Random Element Access (by coordinate)

Slow, O(nnz) linear search

Moderate, O(log(nnz_row)) binary search

Moderate, O(log(nnz_col)) binary search

Slow, requires block lookup + intra-block offset

Row Slice Iteration

Slow, requires scanning all entries

Fast, O(1) row start lookup

Very slow, requires full scan

Fast for aligned rows, variable otherwise

Column Slice Iteration

Slow, requires scanning all entries

Very slow, requires full scan

Fast, O(1) column start lookup

Fast for aligned columns, variable otherwise

Memory Overhead (Index Storage)

High, 2 ints per nnz

Moderate, ~1 int per nnz + row array

Moderate, ~1 int per nnz + col array

Low, indices per block, not per nnz

Ideal Sparsity Pattern

Arbitrary, unstructured

Row-heavy operations, SpMV

Column-heavy operations, SpMV^T

Regular, clustered non-zeros

Sparse Matrix-Vector Multiply (SpMV) Performance

Poor, irregular access

Good, streaming access to x vector

Poor for y = Ax, good for y = A^Tx

Excellent with vectorized block ops

Sparse Matrix-Matrix Multiply (SpMM) Performance

Poor

Good

Good for specific orientations

Excellent with high block utilization

Hardware Kernel Support

Limited, generic only

Widespread (BLAS, cuSPARSE)

Widespread (BLAS, cuSPARSE)

Specialized, requires block-aware kernels

Typical Use Case

Incremental construction, dynamic graphs, simplicity

Scientific computing, linear solvers (most common)

Graph algorithms (transpose ops), certain decompositions

Computer vision, dense sub-structures (e.g., from structured pruning)

SPARSE STORAGE

How COO Format Works in Sparse Model Inference

The COO (Coordinate) Format is a foundational sparse tensor storage scheme that directly encodes the positions and values of non-zero elements, providing a simple but memory-intensive representation crucial for certain sparse model operations.

COO (Coordinate) Format is a sparse tensor storage scheme that explicitly stores a list of (row index, column index, value) tuples for every non-zero element in a matrix or higher-dimensional tensor. This direct coordinate representation offers maximum flexibility for representing irregular, unstructured sparsity patterns generated by techniques like magnitude-based pruning. Its simplicity makes it easy to construct and modify, but the explicit storage of two integer indices per value introduces significant memory overhead for metadata, especially as tensor dimensionality increases.

During sparse model inference, COO is often used as an intermediate or input format before conversion to more compute-efficient layouts like CSR (Compressed Sparse Row). Its primary advantage is efficient random insertion and deletion of non-zeros, which is useful during dynamic sparsity patterns or model assembly. However, for core operations like SpMM (Sparse Matrix-Matrix Multiplication), the format's irregular memory access can lead to load imbalance and poor cache utilization compared to compressed formats, making it less ideal for direct execution on parallel hardware like GPUs without significant kernel optimization.

COO FORMAT

Frequently Asked Questions

The Coordinate (COO) format is a fundamental sparse tensor storage scheme. This FAQ addresses its core mechanics, trade-offs, and role in sparse neural network inference.

The Coordinate (COO) format is a sparse tensor storage scheme that explicitly stores a list of tuples, each containing the indices and value of a non-zero element. For a 2D sparse matrix, each non-zero is represented as a (row_index, column_index, value) triplet. These triplets are typically stored in three parallel arrays (or a single array of structs). The format does not compress index data, making it simple to construct and modify but often less memory-efficient for computation than formats like Compressed Sparse Row (CSR).

How it works:

  • Data Arrays: row_indices[], col_indices[], data[].
  • Storage: The i-th non-zero element has its row index in row_indices[i], column index in col_indices[i], and value in data[i].
  • Access: To iterate all non-zeros, you loop from 0 to nnz-1 (number of non-zeros). Random access by (row, col) is inefficient, requiring a linear scan.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.