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, bicgstab, 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.6b0.tar.gz (1.1 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.6b0-cp313-cp313-manylinux_2_35_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.6b0-cp313-cp313-macosx_14_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

mlx_sparse-0.0.6b0-cp312-cp312-manylinux_2_35_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.6b0-cp312-cp312-macosx_14_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

mlx_sparse-0.0.6b0-cp311-cp311-manylinux_2_35_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.6b0-cp311-cp311-macosx_14_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

mlx_sparse-0.0.6b0-cp310-cp310-manylinux_2_35_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

mlx_sparse-0.0.6b0-cp310-cp310-macosx_14_0_arm64.whl (5.5 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file mlx_sparse-0.0.6b0.tar.gz.

File metadata

  • Download URL: mlx_sparse-0.0.6b0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mlx_sparse-0.0.6b0.tar.gz
Algorithm Hash digest
SHA256 17addfd20db5834ff07d5469e9db70b5acaa77a9a6971d85e178406cb7a74d5c
MD5 218254308be496871ba1ef800459ee19
BLAKE2b-256 9d581ed8e5d1a57867fc0f25b0b12a380b1f0417bbb03229dd13adbccaa3fbbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0.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.6b0-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4ddae60649cb599e7197f8f0c91c431e432a99c7990925091955951413ec360c
MD5 439d24a7305e9bf3521400243120c23b
BLAKE2b-256 afd5d03b84fddafa54d5365b193d2c1000ed6409c1aa6830fb6897d45d153fe7

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b0619f8583578dc9b9181b04a7a419b697b8ec063778a3d382800977ec44893f
MD5 ff3eb4f86c48574264cc2e681d343afe
BLAKE2b-256 bfd01d46b003cbdbd45666c9d45d8da19cc137927d04e327169fb02fd5e23d72

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 087229f69b872b4e6feb40b408e4fa8ccdc96306def46de0f1ff797c733c6d02
MD5 84260737b256b732af907018cbe98663
BLAKE2b-256 85d9820768af7b2a6a426a4b8ec446388c0546851f4e1d6b7db02a2ea99847b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c32332dcf1af7c856e5486969cbc0252ce2ebdf358ca46b8a24a33f7164cb1b6
MD5 8866c4b24c2d844e4ddc54e092b52e98
BLAKE2b-256 32633571713faf1d9bff700bd3847abca5ba37ec4e8aa7ee34f6ee60bf14e5aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 60ac590399ed597ebcde9295a5cb027ba02f575259fea958a675d8749312ce01
MD5 88b20af61b115372c0a524f133d1801d
BLAKE2b-256 02cab83882817b3df511f66018b2068a4f5009fa6914276b6528041ef48d76d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c8ff3f99238e5c6bb387d7e8292ac6ab89e545945cc704d8ee965e7746e0cbd3
MD5 a5cc07333b246d69e1d2b93074a56ff7
BLAKE2b-256 b4fcfdd8f9739ec91964b7fbea48bdee89f262ff0e61aa2afefffdca37b72f0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d47d05a79a8b5932bdbd05ff542c4e6b5f29b6721028a18c989d9a5f6f84859c
MD5 5321c0c9e4e058664c3f4ff12a295e3f
BLAKE2b-256 5a8abe882b3c2db455bd984cb6908e26c153b0ced8f1c02e5692f5de5f2a0092

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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.6b0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.6b0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 993697dec1e880d614aa4b9316ee9288aebb68aa521d30a7a7c098e68e56af54
MD5 1d2aa7beb3e80d7680ba9fb49ac9899e
BLAKE2b-256 c99e2f68d4ba27ca138fcccb040db30eb3a954a5c93d46044791923bde3d4fa3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.6b0-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