Least-squares solvers for MLX with Apple MPS native extensions.
Project description
mlx-lstsq
mlx-lstsq provides least-squares solvers for MLX backed by custom Apple Metal Performance Shaders kernels.
Requirements
- macOS on Apple Silicon
- Python 3.10 or newer
mlx>=0.31.1- Xcode command line tools
Installation
pip install mlx-lstsq
The package contains a compiled extension module plus companion .dylib and .metallib assets, so installation happens from a wheel on supported systems or from source with a local toolchain.
Usage
import mlx.core as mx
import mlx_lstsq
A = mx.array([[1.0, 0.0], [1.0, 1.0], [1.0, 2.0]], dtype=mx.float32)
b = mx.array([1.0, 2.0, 2.5], dtype=mx.float32)
x = mlx_lstsq.solve(A, b)
ridge_x = mlx_lstsq.solve_ridge(A, b, 1e-3)
Performance
The benchmark data in examples/benchmark_solve_backends_n1024.csv sweeps m from 16,384 to 4,194,304 with n = 1024 and compares mlx-lstsq against a Torch MPS-plus-CPU hybrid path and CPU-only SciPy/NumPy Cholesky baselines.
Across the larger supported problem sizes in that sweep, mlx-lstsq is roughly 3.5x to 3.9x faster than the SciPy and NumPy CPU baselines, and about 1.6x to 1.9x faster than the Torch hybrid path before that backend becomes unsupported. You can regenerate the figure with python3 examples/plot_benchmark_solve_backends.py.
Publishing Checklist
python3 -m pip install --upgrade build twine
python3 -m build
python3 -m twine check dist/*
python3 -m unittest discover -s tests -v
The smoke test installs the wheel from dist/ into a fresh virtual environment and verifies a scalar solve, so it checks the publishable artifact instead of the source tree. Run that check on each supported Python version before publishing.
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_lstsq-0.1.1.tar.gz.
File metadata
- Download URL: mlx_lstsq-0.1.1.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1b3c0428a837c45969098322c7f4259cb1b3b20badd026f57891d910c6289f6
|
|
| MD5 |
0da2c8f52cdb253573a94ccfe3044deb
|
|
| BLAKE2b-256 |
a47ae53daa102a6c92bc69306d4835cf339c322449d2e21e69689db56bd34d9f
|
File details
Details for the file mlx_lstsq-0.1.1-cp314-cp314-macosx_26_0_arm64.whl.
File metadata
- Download URL: mlx_lstsq-0.1.1-cp314-cp314-macosx_26_0_arm64.whl
- Upload date:
- Size: 104.1 kB
- Tags: CPython 3.14, macOS 26.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f9e818e28d4fa22660005e06856928821fe2e6562bedda7a7e57b26bdbdc11c
|
|
| MD5 |
12cd3013d8c497eea0fafc48c017f5ab
|
|
| BLAKE2b-256 |
edaf15f141f36f023d14ce72e603d1d1fb0f1a7469e8bb9fd5d9ccf3b515e0d8
|
File details
Details for the file mlx_lstsq-0.1.1-cp313-cp313-macosx_26_0_arm64.whl.
File metadata
- Download URL: mlx_lstsq-0.1.1-cp313-cp313-macosx_26_0_arm64.whl
- Upload date:
- Size: 104.0 kB
- Tags: CPython 3.13, macOS 26.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2caeb812b60db40af9b690f57deb1fb642d58573e364f9b50d4efe41824b7919
|
|
| MD5 |
848c4c034f351f992f1dbc304c329771
|
|
| BLAKE2b-256 |
f7b7c2ad20a809e7330f546aa052c0e55e5dd43b373f823b05dfaf8afd377899
|
File details
Details for the file mlx_lstsq-0.1.1-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: mlx_lstsq-0.1.1-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 104.0 kB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ab3bc4640db5fb915391d4ec4153731c9670c9e36f7d03c09e19ed00bda55a7
|
|
| MD5 |
b542058f55307cdc40c904aeae4d6c26
|
|
| BLAKE2b-256 |
e5e5eb1fed8dfc54277ec9a25e718e2e166c056b8c1ba305ec98098035f49736
|
File details
Details for the file mlx_lstsq-0.1.1-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: mlx_lstsq-0.1.1-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 104.4 kB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fc8e7a56e614c3a5fafbc6d580a8da02784d715497a2ee962a7962876713515
|
|
| MD5 |
5f0d50123e1a6a2289151786d6f1f64f
|
|
| BLAKE2b-256 |
eadd05872c9b3d322e4377227bbe9351022edde2e6fca1bc2dbd7f71a843049d
|
File details
Details for the file mlx_lstsq-0.1.1-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: mlx_lstsq-0.1.1-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 104.4 kB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5272d8bb1f50d7c2cf438b64fc96d3aaf5b60f77a6b92c196d1181e5dd898ae
|
|
| MD5 |
472a411680d980eaca17c8b398df6b30
|
|
| BLAKE2b-256 |
18940e8c753da531e318d626793d1df05e676f89b8a96287228da62ee62d6519
|