Sparse array containers and primitives for MLX
Project description
mlx-sparse
Warning: beta release This is an early beta. 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 here).
Platform 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 and CSR for 2D sparse arrays. Current
functionality includes construction, validation, COO to CSR, CSR to dense, CSR
canonicalization, CSR matrix-vector multiply, CSR matrix-matrix multiply,
batched dense RHS products, CSR sparse-sparse products, transpose, Hermitian
transpose. mlx-sparse also supports sparse linalg solvers (cg, gmres, minres), 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
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.3b0.tar.gz.
File metadata
- Download URL: mlx_sparse-0.0.3b0.tar.gz
- Upload date:
- Size: 373.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2ad87229977d741fe99892f32ec0310b649cc76ed6a591417cd0d4494687d01
|
|
| MD5 |
a93b23dd0b6d1766c366bce4c5a7a08b
|
|
| BLAKE2b-256 |
c5145ccba34c7271646b930a4e1824d668364954537d3bfdeea7c660622f57e0
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.3b0.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.3b0.tar.gz -
Subject digest:
b2ad87229977d741fe99892f32ec0310b649cc76ed6a591417cd0d4494687d01 - Sigstore transparency entry: 1629246489
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Branch / Tag:
refs/tags/v0.0.3b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.3b0-cp313-cp313-macosx_14_0_universal2.whl.
File metadata
- Download URL: mlx_sparse-0.0.3b0-cp313-cp313-macosx_14_0_universal2.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.13, macOS 14.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d52662d0d0ccce1dac72743075dc9b6d3d181c43faf84d01a8be93191dd390a8
|
|
| MD5 |
f0dec95ed183a94e6bfc6dbbd80146f3
|
|
| BLAKE2b-256 |
dfaa9b685a2bfc125fcd5173dc56ef9cb55372175e70f6c9dce73db3fa1fb10d
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.3b0-cp313-cp313-macosx_14_0_universal2.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.3b0-cp313-cp313-macosx_14_0_universal2.whl -
Subject digest:
d52662d0d0ccce1dac72743075dc9b6d3d181c43faf84d01a8be93191dd390a8 - Sigstore transparency entry: 1629246527
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Branch / Tag:
refs/tags/v0.0.3b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.3b0-cp312-cp312-macosx_14_0_universal2.whl.
File metadata
- Download URL: mlx_sparse-0.0.3b0-cp312-cp312-macosx_14_0_universal2.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.12, macOS 14.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07ff657941cf0d46f79d0448599926bd3cf53bcef44aa84852e2d987bd85538d
|
|
| MD5 |
66bd8f962e80bb9dfbe7b987095713ca
|
|
| BLAKE2b-256 |
7af12d21d85c48238df9316e9587c07d4e96b9e399257611b1b80e39a394f867
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.3b0-cp312-cp312-macosx_14_0_universal2.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.3b0-cp312-cp312-macosx_14_0_universal2.whl -
Subject digest:
07ff657941cf0d46f79d0448599926bd3cf53bcef44aa84852e2d987bd85538d - Sigstore transparency entry: 1629246501
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Branch / Tag:
refs/tags/v0.0.3b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.3b0-cp311-cp311-macosx_14_0_universal2.whl.
File metadata
- Download URL: mlx_sparse-0.0.3b0-cp311-cp311-macosx_14_0_universal2.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.11, macOS 14.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4238737821d764606b3a354322761014f0a7ee18151326539223d3a95e58bfd
|
|
| MD5 |
8cb1a05918428eba3410af9d5f6f787e
|
|
| BLAKE2b-256 |
0e795e5dd43433cca8976c0ab2117ca29081f053dd5dbe6394e2d188b0840661
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.3b0-cp311-cp311-macosx_14_0_universal2.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.3b0-cp311-cp311-macosx_14_0_universal2.whl -
Subject digest:
d4238737821d764606b3a354322761014f0a7ee18151326539223d3a95e58bfd - Sigstore transparency entry: 1629246520
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Branch / Tag:
refs/tags/v0.0.3b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mlx_sparse-0.0.3b0-cp310-cp310-macosx_14_0_universal2.whl.
File metadata
- Download URL: mlx_sparse-0.0.3b0-cp310-cp310-macosx_14_0_universal2.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.10, macOS 14.0+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77c355a420ba1cc35cdd83888ba679c650579ceba4a07519ec93dcb20c5536b3
|
|
| MD5 |
d3c03ff3fd645334cc31b170eb766120
|
|
| BLAKE2b-256 |
2ce62fb0a543f39e0a6311875e18eef355f7f7b494073d1a6e735166fd75a444
|
Provenance
The following attestation bundles were made for mlx_sparse-0.0.3b0-cp310-cp310-macosx_14_0_universal2.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.3b0-cp310-cp310-macosx_14_0_universal2.whl -
Subject digest:
77c355a420ba1cc35cdd83888ba679c650579ceba4a07519ec93dcb20c5536b3 - Sigstore transparency entry: 1629246550
- Sigstore integration time:
-
Permalink:
waleed-sh/mlx-sparse@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Branch / Tag:
refs/tags/v0.0.3b0 - Owner: https://github.com/waleed-sh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@9e69824cf7870fd6ff74afe07b96af84eaffc812 -
Trigger Event:
push
-
Statement type: