Fork me on GitHub

Sparse matrices, in pure Go.
Solvers that count iterations like SciPy.

go-sparse is the sparse linear algebra layer of the Go scientific stack built on go-ndarray: sparse formats, fill-reducing orderings and iterative solvers with preconditioners, following scipy.sparse.linalg. Its tests replay recorded SciPy answers. No cgo. sparse v0.1.0 is released; what is not provided yet (sparse direct factorisations, eigensolvers, multigrid) is said in the documentation.

CG, GMRES, MINRES, LSQR, LSMR iteration counts equal SciPy's0.56โ€“0.98ร— SciPy's time on one core100% statement coverage
main.go
a := gallery.Laplacian2D(100, 100)           // *sparse.CSR[float64]
b := make([]float64, a.Rows)
ic, _ := iter.NewIC0(a)                      // incomplete Cholesky
res, _ := iter.CG(a, b, &iter.Options{RTol: 1e-8, M: ic})
fmt.Println(res.Info, res.Iterations)        // 0 = converged, as in SciPy
3 repositories โ€” one library, released v0.1.0: go get github.com/go-sparse/sparse@v0.1.0
Why go-sparse

What scipy.sparse gives, in Go.

Each package names the reference it corresponds to: SciPy's scipy.sparse and scipy.sparse.linalg, MATLAB's sparse functions, and SuiteSparse AMD and COLAMD as the reference algorithms for the orderings.

โ–ฆ

Sparse formats

COO, CSR, CSC and DOK over float64 and complex128; conversions, O(1) transpose, SpMV, SpMM, SpGEMM, Diags, Tril, Triu and norms.

โ‡„

Orderings

RCM, AMD and COLAMD, with bandwidth, profile and Cholesky and QR fill counts to compare them.

โ†ป

Iterative solvers

CG, GMRES(m), BiCGSTAB, MINRES, LSQR and LSMR, with Jacobi, SSOR, IC0, ILU0 and ILUT preconditioners, on any LinearOperator.

๐Ÿ“„

Matrix Market

Read and write coordinate and array files, real, integer, pattern and complex, with limits against hostile input.

๐Ÿงฎ

On go-ndarray

The nd package takes and returns *ndarray.Array for vectors, dense matrices, SpMV and SpMM.

๐Ÿ“ฆ

Pure Go, CGO=0

No cgo. CI runs the tests with the race detector, on 386 and the other architectures of the fleet.

โš–๏ธ

BSD-3-Clause

Every repository of the organization. The orderings are written from the papers; GPL and LGPL code was not consulted.

What is checked

6 kinds of check, each against a recorded answer.

The fixtures are written by a Go harness that calls SciPy 1.18.1, committed, and compared in the tests. The performance table is in the library's docs/perf.md and the documentation, measured against SciPy on one core.

Iteration counts equal SciPy's

CG, GMRES, MINRES, LSQR and LSMR take the same number of iterations as SciPy 1.18.1 on the committed suite; BiCGSTAB agrees within a few iterations. The stopping rule, rtol, maxiter and info follow scipy.sparse.linalg. (sparse)

Orderings measured by fill

AMD Cholesky fill is within 1% of SuiteSparse AMD, COLAMD LU fill within 4% of SuperLU’s COLAMD, and RCM bandwidth equals SciPy’s. Tie-breaking differs, so permutations differ; quality is compared by fill. (sparse)

Faster than SciPy on one core

SpMV, CG and GMRES(30) on 2-D Laplacians of 1.1e5 and 1e6 nonzeros take 0.56 to 0.98 of SciPy’s time (Go time / SciPy time), interleaved on one core, measured on 2026-10-20 at load 5; SpMV is bit-identical to SciPy’s csr_matvec order. (sparse)

Recorded answers, no Python at test time

A Go harness drives SciPy over a pipe and records the answers in a committed fixture; the regression tests replay it, so they need neither Python nor network. (sparse)

Hostile Matrix Market files

mtx.Read checks declared sizes before allocating, counts stored values in int64, cuts a gzip bomb off at a byte limit, and has a fuzz target with a committed corpus. (sparse)

100% statement coverage

go test -race with 100% statement coverage over all packages, 386 and the other architectures in CI, and govulncheck. (sparse)

Repositories

What is here.

sparse

library ยท released v0.1.0

Released v0.1.0. COO, CSR, CSC and DOK matrices over float64 and complex128, Matrix Market I/O, the RCM, AMD and COLAMD orderings, and the iterative solvers CG, GMRES, BiCGSTAB, MINRES, LSQR and LSMR with Jacobi, SSOR, IC0, ILU0 and ILUT preconditioners, following scipy.sparse.linalg.

docs

site

The documentation (Hugo + Hextra): one section per library, made of its own README and what it verifies and measures. Source โ†’

brand

assets

Logos and icons for the organization, in SVG / PNG / JPG / ICO / ICNS across colour, white and black variants.

Sparse linear algebra for the Go scientific stack.

go-sparse works with the arrays of go-ndarray, next to go-numerics and go-statistics, and a go-notebook cell can use all of them. What is not provided yet is listed in the documentation.

Read the source on GitHub โ†’