Sparse array containers and primitives for MLX
Project description
mlx-sparse
[!WARNING] This is an early beta. macOS and Linux are supported, but Linux is CPU-only in this release. 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. Linux wheels use native CPU kernels only, there is no CUDA, ROCm, Accelerate, BLAS, or Sparse BLAS backend on Linux yet.
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. Published Linux wheels are CPU-only. For editable/source macOS builds, enable the same Accelerate 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_cpu()
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 macOS wheels ship that metallib beside the Python package. Linux wheels do
not build or ship Metal assets.
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.5b0.tar.gz.
File metadata
- Download URL: mlx_sparse-0.0.5b0.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f4bf3e1a4c780d28fea49f2e08f8e312bd33b4b69333389db83ca3bac915a81
|
|
| MD5 |
b2a033bad31428cb0fe2ab266a347429
|
|
| BLAKE2b-256 |
cb63b98674ae0d6a683501116a36016dfb2f63ca42c4e14511ea1c182b799b77
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0.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.5b0.tar.gz -
Subject digest:
7f4bf3e1a4c780d28fea49f2e08f8e312bd33b4b69333389db83ca3bac915a81 - Sigstore transparency entry: 1702732904
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp313-cp313-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp313-cp313-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bd986fdf77df393ae916df226e37338778880cb4f025a0c77d9305c3e8c4029
|
|
| MD5 |
99eaf4278ae3a82a41d322df63dc2b98
|
|
| BLAKE2b-256 |
563fd8b8bfd30e303fe1cac016c53a3478a7063c1081477154d639c1bc9d8c56
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-cp313-cp313-manylinux_2_35_x86_64.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.5b0-cp313-cp313-manylinux_2_35_x86_64.whl -
Subject digest:
4bd986fdf77df393ae916df226e37338778880cb4f025a0c77d9305c3e8c4029 - Sigstore transparency entry: 1702733265
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp313-cp313-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp313-cp313-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.6 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 |
a3efcfae9f6e17dd7e316d94772273a1578396ee525ffac90830a84d56c84328
|
|
| MD5 |
52ee970f51c46339d20dcc2b393dcf72
|
|
| BLAKE2b-256 |
e458361cb746f124b6bc9f66fa8cd021a1d06ff798268b889c0cde88479f45ec
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-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.5b0-cp313-cp313-macosx_14_0_arm64.whl -
Subject digest:
a3efcfae9f6e17dd7e316d94772273a1578396ee525ffac90830a84d56c84328 - Sigstore transparency entry: 1702733341
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp312-cp312-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp312-cp312-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a502d93e492e03711cfc6655cc152d67c466768e156e61c2e4d21a77c8320cb
|
|
| MD5 |
ecc38ac87127e2a46806f185c133704b
|
|
| BLAKE2b-256 |
216b5d611d5855d50db366eda23d9d77a06c4c637fef8cb5520fcb61327461f0
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-cp312-cp312-manylinux_2_35_x86_64.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.5b0-cp312-cp312-manylinux_2_35_x86_64.whl -
Subject digest:
7a502d93e492e03711cfc6655cc152d67c466768e156e61c2e4d21a77c8320cb - Sigstore transparency entry: 1702733112
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.6 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 |
4e95f1cbb17b375a0c542c03aac480384a5be0e5a3cc94d7cf072c8093f36238
|
|
| MD5 |
1b117834ca23c8c0a4c3494756981cd2
|
|
| BLAKE2b-256 |
a62acb1324734cfceedbb57013630dd651d38426c9d463ba4862384ea32174e4
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-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.5b0-cp312-cp312-macosx_14_0_arm64.whl -
Subject digest:
4e95f1cbb17b375a0c542c03aac480384a5be0e5a3cc94d7cf072c8093f36238 - Sigstore transparency entry: 1702733643
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp311-cp311-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp311-cp311-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9eceb9dd05f5c76d039140149576798b648f16036f29214d2a813d555119ef91
|
|
| MD5 |
6697f688c2ab5be99e25a4e41ffa370b
|
|
| BLAKE2b-256 |
6e46042b3b826b91ab1120e9f693528aba85ea0d8adb1327bac704f75cf845f8
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-cp311-cp311-manylinux_2_35_x86_64.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.5b0-cp311-cp311-manylinux_2_35_x86_64.whl -
Subject digest:
9eceb9dd05f5c76d039140149576798b648f16036f29214d2a813d555119ef91 - Sigstore transparency entry: 1702733479
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp311-cp311-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp311-cp311-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.6 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 |
0e7fd06db5d44b5fee2f44b1dbe719b04b9b97c47a44d191e254494793bdc7c1
|
|
| MD5 |
5d63952b65257fa00d8e2dacf70ce2be
|
|
| BLAKE2b-256 |
a84b0e71cb60445b6f919f5118d7da623beb27205981cc291120ae61ce89f210
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-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.5b0-cp311-cp311-macosx_14_0_arm64.whl -
Subject digest:
0e7fd06db5d44b5fee2f44b1dbe719b04b9b97c47a44d191e254494793bdc7c1 - Sigstore transparency entry: 1702732992
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp310-cp310-manylinux_2_35_x86_64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp310-cp310-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f461aca093972b44273d330cbd5a7a46351e13b3b270465409e7fdb1eca4d34
|
|
| MD5 |
02dd69dc0b2ba476019929185c7ada4c
|
|
| BLAKE2b-256 |
add48d08f085f45a362b077be128833c812f0545e83fb25af0450eaf334eb1a3
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-cp310-cp310-manylinux_2_35_x86_64.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.5b0-cp310-cp310-manylinux_2_35_x86_64.whl -
Subject digest:
4f461aca093972b44273d330cbd5a7a46351e13b3b270465409e7fdb1eca4d34 - Sigstore transparency entry: 1702733558
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.5b0-cp310-cp310-macosx_14_0_arm64.whl.
File metadata
- Download URL: mlx_sparse-0.0.5b0-cp310-cp310-macosx_14_0_arm64.whl
- Upload date:
- Size: 4.6 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 |
6101e5fff15f5de98b951fd17ac0cb627fb294ad2e8e76dc569b249aae0a493e
|
|
| MD5 |
febc7b4ed2cff8168ac7044a4312608d
|
|
| BLAKE2b-256 |
f79dc2cd4dbdac3329d2eff3d83102cb29acd2999c6d4749be260d1f3a7810fb
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.5b0-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.5b0-cp310-cp310-macosx_14_0_arm64.whl -
Subject digest:
6101e5fff15f5de98b951fd17ac0cb627fb294ad2e8e76dc569b249aae0a493e - Sigstore transparency entry: 1702733204
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Branch / Tag:
refs/tags/v0.0.5b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@5e0bfcaf3152b5d03eeda58014d5cb4fca0fe19d -
Trigger Event:
push
-
Statement type: