Sparse array containers and primitives for MLX
Project description
mlx-sparse
[!WARNING] This is an early beta. It currently supports only Apple systems. APIs may change, bugs are expected, and some features are still incomplete, especially GPU kernels for various operations. Feedback and issue reports are very welcome!
A lot of the functionality is new and is currently being tested. We welcome any and all feedback! Not all solvers are GPU supported (see the solver support matrix).
[!NOTE] GPU support in this version is Apple Silicon Metal only. CUDA is not currently supported.
mlx-sparse is an attempt at an MLX-native sparse array package. The public API is Python,
while performance-critical operations are implemented as MLX primitives in C++
with CPU backends and Metal kernels for fixed-shape sparse operations.
The supported format surface is COO, CSR, and CSC for 2D sparse arrays. Current
functionality includes construction, validation, format conversions,
canonicalization, sparse-dense products, batched dense RHS products,
sparse-sparse products, transpose, and Hermitian transpose. mlx-sparse also
supports sparse linalg solvers (cg, gmres, minres), reusable direct solves
(factorized), sparse spectral routines (eigsh, eigs, svds), sparse
Cholesky/LU factors, sparse triangular solves, sparse dot/vdot, and autodiff
through sparse values and dense RHS operands, including complex64.
Supported value dtypes are float32, float16, bfloat16, and complex64.
Supported index dtypes are int32 and int64 on CPU and GPU.
Quick Start
Install from PyPI:
python -m pip install mlx-sparse
Published macOS wheels are built with optional Apple Accelerate sparse direct solver support enabled. For editable/source builds, enable the same path with:
CMAKE_ARGS="-DMLX_SPARSE_ENABLE_ACCELERATE=ON" python -m pip install -e .
See the full installation guide for platform requirements, feature gates, and verification commands.
import mlx.core as mx
import numpy as np
import mlx_sparse as ms
ms.use_gpu()
data = [2.0, -1.0, 4.0]
row = [0, 0, 1]
col = [0, 2, 1]
a = ms.coo_array((data, (row, col)), shape=(2, 3)).tocsr(canonical=True)
x = mx.array(np.array([3.0, 10.0, 7.0], dtype=np.float32))
y = a @ x
dense = a.todense()
at = a.T
b = mx.array(np.array([1.0, 2.0], dtype=np.float32))
spd = ms.csr_array(
(
[4.0, 1.0, 1.0, 3.0],
[0, 1, 0, 1],
[0, 2, 4],
),
shape=(2, 2),
canonical=True,
)
solution, info = ms.linalg.cg(spd, b)
factor = ms.linalg.sparse_cholesky(spd)
The package build compiles src/sparse/*.metal into
mlx_sparse/mlx_sparse.metallib when the macOS Metal toolchain is available,
and the wheel ships that metallib beside the Python package.
Development
For contributors, use an editable install from the repository root. This builds the native extension and installs the development tooling.
python -m pip install -e ".[dev]"
License
This package is licensed under the Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 mlx_sparse-0.0.4b0.tar.gz.
File metadata
- Download URL: mlx_sparse-0.0.4b0.tar.gz
- Upload date:
- Size: 435.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
770f73b4bb09bee1a92148359efe371ba82f57ade58b925d93af418392cb8dd6
|
|
| MD5 |
1a54af2da8750833fdebafc76aeba9b2
|
|
| BLAKE2b-256 |
a606622593d57d487b40277bcaaaae4526223c4895fe79237f78da4dd8c41d70
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.4b0.tar.gz:
Publisher:
publish.yaml on waleed-sh/mlx-sparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_sparse-0.0.4b0.tar.gz -
Subject digest:
770f73b4bb09bee1a92148359efe371ba82f57ade58b925d93af418392cb8dd6 - Sigstore transparency entry: 1651090125
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Branch / Tag:
refs/tags/v0.0.4b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.4b0-cp313-cp313-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.4b0-cp313-cp313-macosx_14_0_arm64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.13, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b0a2c1258cd448bba6c54211caf6dc770657ed53d4115ee8a024b614bce087
|
|
| MD5 |
b8e7697eebab66e63de76fe8f6cc960e
|
|
| BLAKE2b-256 |
d02902e349f2118e41e3d9cf8782f82edf269c9b4a5718d34d23ed596cea7396
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.4b0-cp313-cp313-macosx_14_0_arm64.whl:
Publisher:
publish.yaml on waleed-sh/mlx-sparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_sparse-0.0.4b0-cp313-cp313-macosx_14_0_arm64.whl -
Subject digest:
e8b0a2c1258cd448bba6c54211caf6dc770657ed53d4115ee8a024b614bce087 - Sigstore transparency entry: 1651090299
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Branch / Tag:
refs/tags/v0.0.4b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.4b0-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.4b0-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04998acd56a2b45c47b28033250241481a5d548993d01b3045658516d21bfc9b
|
|
| MD5 |
a318d4793ff7bbcd838faa78045cbec4
|
|
| BLAKE2b-256 |
35edb8d3d632b3fba1257378020316f70040b0763f3c14a19b2793503ebb0db2
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.4b0-cp312-cp312-macosx_14_0_arm64.whl:
Publisher:
publish.yaml on waleed-sh/mlx-sparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_sparse-0.0.4b0-cp312-cp312-macosx_14_0_arm64.whl -
Subject digest:
04998acd56a2b45c47b28033250241481a5d548993d01b3045658516d21bfc9b - Sigstore transparency entry: 1651090459
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Branch / Tag:
refs/tags/v0.0.4b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.4b0-cp311-cp311-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.4b0-cp311-cp311-macosx_14_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.11, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92cdcc26a6338da0505f50d022bfbce5dbc0ad111a668eac24857049be36d4d2
|
|
| MD5 |
408fd1a1f0f4a89af427111af27bf108
|
|
| BLAKE2b-256 |
06da98265d1840816dd2d4d37573d78463d9e97b8986b2ac5a1eb94dc68ce42d
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.4b0-cp311-cp311-macosx_14_0_arm64.whl:
Publisher:
publish.yaml on waleed-sh/mlx-sparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_sparse-0.0.4b0-cp311-cp311-macosx_14_0_arm64.whl -
Subject digest:
92cdcc26a6338da0505f50d022bfbce5dbc0ad111a668eac24857049be36d4d2 - Sigstore transparency entry: 1651090382
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Branch / Tag:
refs/tags/v0.0.4b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.4b0-cp310-cp310-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.4b0-cp310-cp310-macosx_14_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.10, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ab6f42fbd4475fbb10d8d7bca77c962e1302e244e345648884699c5a78d788f
|
|
| MD5 |
f800c2b0178c2303ffe7077fb8368882
|
|
| BLAKE2b-256 |
a86db1ed494de7deccfda871b6dfb69550efe1e76ff1a4a7c8139aae0ea74b86
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.4b0-cp310-cp310-macosx_14_0_arm64.whl:
Publisher:
publish.yaml on waleed-sh/mlx-sparse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mlx_sparse-0.0.4b0-cp310-cp310-macosx_14_0_arm64.whl -
Subject digest:
3ab6f42fbd4475fbb10d8d7bca77c962e1302e244e345648884699c5a78d788f - Sigstore transparency entry: 1651090210
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Branch / Tag:
refs/tags/v0.0.4b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@b7c9850f8fe64fc84a18c306dd9194f63d86080d -
Trigger Event:
push
-
Statement type: