Skip to main content

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. Feedback and issue reports are very welcome!

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, 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 = mx.array(np.array([2.0, -1.0, 4.0], dtype=np.float32))
row = mx.array(np.array([0, 0, 1], dtype=np.int32))
col = mx.array(np.array([0, 2, 1], dtype=np.int32))

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

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


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.1b0.tar.gz (118.6 kB 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.1b0-cp313-cp313-macosx_14_0_universal2.whl (439.1 kB view details)

Uploaded CPython 3.13macOS 14.0+ universal2 (ARM64, x86-64)

mlx_sparse-0.0.1b0-cp312-cp312-macosx_14_0_universal2.whl (439.1 kB view details)

Uploaded CPython 3.12macOS 14.0+ universal2 (ARM64, x86-64)

mlx_sparse-0.0.1b0-cp311-cp311-macosx_14_0_universal2.whl (439.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ universal2 (ARM64, x86-64)

mlx_sparse-0.0.1b0-cp310-cp310-macosx_14_0_universal2.whl (439.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: mlx_sparse-0.0.1b0.tar.gz
  • Upload date:
  • Size: 118.6 kB
  • 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.1b0.tar.gz
Algorithm Hash digest
SHA256 906235dd407728395d33b0cb87f61e277fa9f076c180c9b76729d805f4456cfa
MD5 690e7d418fca9a3ab75277b7f7993443
BLAKE2b-256 a068daf6e265ec553d1f7c1cf099d2d53ba01e5c9b493cf8639244c3312ea112

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.1b0.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.1b0-cp313-cp313-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.1b0-cp313-cp313-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 f68e1b6a44722394232e817425ad60261372d3c7168f6e963927f42066f6fdc8
MD5 cf86b5d0221a17ad23988f3f840f634e
BLAKE2b-256 6ccf43f88bf7d4cd4623b39eacd0f0324dfe786244559342b032e14cf19fe7d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.1b0-cp313-cp313-macosx_14_0_universal2.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.1b0-cp312-cp312-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.1b0-cp312-cp312-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 7dc60753650f2e17e22848af6f6cdc4a6859b746aea16556bc46dcbf3e702ec2
MD5 704d5bf4af3a3a9710b8adeb528a3fc1
BLAKE2b-256 c94eacf7c27578270bba549d46fd5bc08547f1a95a50694acae0847f1d908c81

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.1b0-cp312-cp312-macosx_14_0_universal2.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.1b0-cp311-cp311-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.1b0-cp311-cp311-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 c683c142f63985b194266e60f5c23ae9251db3afba0f1ba722ac59bf84444543
MD5 eade9b5d3024c8ceadc1c8a8cced4728
BLAKE2b-256 402c174c3e66c50e59c73ce01fa65e6411d868212826e6ed7ade1aecc08f8ef8

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.1b0-cp311-cp311-macosx_14_0_universal2.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.1b0-cp310-cp310-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for mlx_sparse-0.0.1b0-cp310-cp310-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 30385230ab1b6e884f70453b894e9a730743e74dc624c8eaaaa518f935b05d8d
MD5 8a9d81c3ff2806258ebc694f7f78a817
BLAKE2b-256 ac6497b21f622af40b9f9168a06903732341f38ea0907b4ffaa8213001f618da

See more details on using hashes here.

Provenance

The following attestation bundles were made for mlx_sparse-0.0.1b0-cp310-cp310-macosx_14_0_universal2.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