Skip to main content

Sparse array containers and primitives for MLX

Project description

mlx-sparse

PyPI License Documentation Status codecov

[!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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlx_sparse-0.0.5b0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mlx_sparse-0.0.5b0-cp313-cp313-manylinux_2_35_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.5b0-cp313-cp313-macosx_14_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

mlx_sparse-0.0.5b0-cp312-cp312-manylinux_2_35_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.5b0-cp312-cp312-macosx_14_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

mlx_sparse-0.0.5b0-cp311-cp311-manylinux_2_35_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.5b0-cp311-cp311-macosx_14_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

mlx_sparse-0.0.5b0-cp310-cp310-manylinux_2_35_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.5b0-cp310-cp310-macosx_14_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

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

Hashes for mlx_sparse-0.0.5b0.tar.gz
Algorithm Hash digest
SHA256 7f4bf3e1a4c780d28fea49f2e08f8e312bd33b4b69333389db83ca3bac915a81
MD5 b2a033bad31428cb0fe2ab266a347429
BLAKE2b-256 cb63b98674ae0d6a683501116a36016dfb2f63ca42c4e14511ea1c182b799b77

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.5b0.tar.gz:

Publisher: publish.yaml on waleed-sh/mlx-sparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4bd986fdf77df393ae916df226e37338778880cb4f025a0c77d9305c3e8c4029
MD5 99eaf4278ae3a82a41d322df63dc2b98
BLAKE2b-256 563fd8b8bfd30e303fe1cac016c53a3478a7063c1081477154d639c1bc9d8c56

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a3efcfae9f6e17dd7e316d94772273a1578396ee525ffac90830a84d56c84328
MD5 52ee970f51c46339d20dcc2b393dcf72
BLAKE2b-256 e458361cb746f124b6bc9f66fa8cd021a1d06ff798268b889c0cde88479f45ec

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7a502d93e492e03711cfc6655cc152d67c466768e156e61c2e4d21a77c8320cb
MD5 ecc38ac87127e2a46806f185c133704b
BLAKE2b-256 216b5d611d5855d50db366eda23d9d77a06c4c637fef8cb5520fcb61327461f0

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4e95f1cbb17b375a0c542c03aac480384a5be0e5a3cc94d7cf072c8093f36238
MD5 1b117834ca23c8c0a4c3494756981cd2
BLAKE2b-256 a62acb1324734cfceedbb57013630dd651d38426c9d463ba4862384ea32174e4

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9eceb9dd05f5c76d039140149576798b648f16036f29214d2a813d555119ef91
MD5 6697f688c2ab5be99e25a4e41ffa370b
BLAKE2b-256 6e46042b3b826b91ab1120e9f693528aba85ea0d8adb1327bac704f75cf845f8

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0e7fd06db5d44b5fee2f44b1dbe719b04b9b97c47a44d191e254494793bdc7c1
MD5 5d63952b65257fa00d8e2dacf70ce2be
BLAKE2b-256 a84b0e71cb60445b6f919f5118d7da623beb27205981cc291120ae61ce89f210

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4f461aca093972b44273d330cbd5a7a46351e13b3b270465409e7fdb1eca4d34
MD5 02dd69dc0b2ba476019929185c7ada4c
BLAKE2b-256 add48d08f085f45a362b077be128833c812f0545e83fb25af0450eaf334eb1a3

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mlx_sparse-0.0.5b0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.5b0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6101e5fff15f5de98b951fd17ac0cb627fb294ad2e8e76dc569b249aae0a493e
MD5 febc7b4ed2cff8168ac7044a4312608d
BLAKE2b-256 f79dc2cd4dbdac3329d2eff3d83102cb29acd2999c6d4749be260d1f3a7810fb

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page