splineax
Sparse linear operators and direct solvers for Lineax.
splineax lets you keep a linear system in its native sparse storage
(jax.experimental.sparse.BCOO / BCSR) and solve it with a sparse direct solver that
plugs straight into lineax.linear_solve. It also interfaces with asdex for calculating sparse Jacobians and using them as operators.
- Operators:
BCOOLinearOperator,BCSRLinearOperator,SparseJacobianLinearOperator. - Stateful solver protocols:
StatefulSolverandSparseLinearSolverfor writing solver-agnostic code that reuses factorizations over many solves and operators. - Solver library bindings:
Spsolve(any backend),KLU(CPU-only, SuiteSparse KLU), andPardiso(CPU-only, Intel oneMKL Pardiso, installed as extra).KLUandPardisoreuse their factorization across solves. - Higher-level solvers:
AutoSparseLinearSolver, which picks an appropriate solver based on platform and settings, andIterativeRefinement, which wraps any solver and refines its solution to a target residual. - Lineax code interop:
stateful_solve_transformrewrites a function that callslineax.linear_solveso its solves thread a solver state and reuse a factorization.
Installation
pip install splineax
Example
Solve a 10000 x 10000 system. As a dense matrix it would need 10^8 entries, but kept sparse it has only ~3 x 10^4 nonzeros, and the solver never materialises the dense form.
import jax.numpy as jnp
import lineax as lx
import numpy as np
from jax.experimental.sparse import BCOO
import splineax as splx
n = 10000
np.random.seed(0)
# A large, randomly sparse matrix with a heavy diagonal (so it is invertible).
diagonal_indices = np.stack([np.arange(n), np.arange(n)], axis=1)
off_diagonal_indices = np.unique(np.random.randint(0, n, size=(2 * n, 2)), axis=0)
indices = jnp.concatenate([diagonal_indices, off_diagonal_indices])
values = jnp.concatenate(
[
np.full(n, float(n)),
np.random.uniform(low=-1, high=1, size=off_diagonal_indices.shape[0]),
]
)
matrix = BCOO((values, indices), shape=(n, n)).sum_duplicates()
operator = splx.BCOOLinearOperator(matrix)
vectors = [jnp.ones(n), jnp.arange(n) % 2]
solver = splx.AutoSparseLinearSolver()
# Solve once, then thread the returned state back in to reuse the factorization.
solution, state = splx.linear_solve(operator, vectors[0], solver)
assert jnp.allclose(matrix @ solution.value, vectors[0], atol=1e-4)
solution, state = splx.linear_solve(operator, vectors[1], solver, state=state)
assert jnp.allclose(matrix @ solution.value, vectors[1], atol=1e-4)
# Free the factorization when you are done with it.
state.release()
Documentation
Build the docs locally with uv run mkdocs serve, or view the user guide and API reference here.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splineax-0.3.0.tar.gz.
File metadata
- Download URL: splineax-0.3.0.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61aed8f3b274cf1d09f962fb379304f63ef21ef74b5b33d368072d487d359cfa
|
|
| MD5 |
c22a4799cc2f3c624c6776b100b5e773
|
|
| BLAKE2b-256 |
15d4733b368eb5c08f3e4e7b7688ad7350a8e82b265b1cd6523d2df10e7292d5
|
Provenance
The following attestation bundles were made for splineax-0.3.0.tar.gz:
Publisher:
release.yml on nardi/splineax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
splineax-0.3.0.tar.gz -
Subject digest:
61aed8f3b274cf1d09f962fb379304f63ef21ef74b5b33d368072d487d359cfa - Sigstore transparency entry: 2655308679
- Sigstore integration time:
-
Permalink:
nardi/splineax@940293e06fa27a9575f667cbab7cd320cf9d026a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/nardi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@940293e06fa27a9575f667cbab7cd320cf9d026a -
Trigger Event:
release
-
Statement type:
File details
Details for the file splineax-0.3.0-py3-none-any.whl.
File metadata
- Download URL: splineax-0.3.0-py3-none-any.whl
- Upload date:
- Size: 52.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb698953cba62b9be4fb8d0577746604a238a93c08342c7c43426b2e0ccdb7d7
|
|
| MD5 |
97e1c945da14cf58f28685100a4e9dc2
|
|
| BLAKE2b-256 |
f9f46de1fe7bdb9f808f1491277530805bbb6bfa32ca9e70ea80c0c6fdd0a72a
|
Provenance
The following attestation bundles were made for splineax-0.3.0-py3-none-any.whl:
Publisher:
release.yml on nardi/splineax
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
splineax-0.3.0-py3-none-any.whl -
Subject digest:
bb698953cba62b9be4fb8d0577746604a238a93c08342c7c43426b2e0ccdb7d7 - Sigstore transparency entry: 2655308682
- Sigstore integration time:
-
Permalink:
nardi/splineax@940293e06fa27a9575f667cbab7cd320cf9d026a -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/nardi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@940293e06fa27a9575f667cbab7cd320cf9d026a -
Trigger Event:
release
-
Statement type: