Skip to main content

fastslim

PyPI CI Python License

SLIM (Sparse Linear Methods, Ning & Karypis 2011) learns a sparse, non-negative item-item weight matrix W from a user-item matrix X and scores users with one sparse product, X @ W. Every recommendation is explainable: "because you interacted with these items".

fastslim is a Rust implementation behind a small Python API. The solver is exact (the returned weights satisfy the optimality conditions of the objective below), deterministic (bit-identical output for any thread count) and fast: MovieLens 1M fits in about a second.

Install

pip install fastslim

Wheels for Linux (x86_64, aarch64), macOS and Windows, Python 3.10 and newer. Runtime dependencies are NumPy and SciPy.

Usage

import numpy as np
from scipy import sparse

import fastslim

rng = np.random.default_rng(0)
X = sparse.csr_matrix((rng.random((2000, 300)) < 0.03).astype(np.float64))  # users x items

W = fastslim.fit(X, lambd=2.0, beta=2.0)      # items x items, sparse, zero diagonal
top = fastslim.recommend(W, X[:5], k=10)       # top-10 unseen items for five users
scores = fastslim.predict(W, X[0])             # raw scores for one user

The same solver as an estimator:

from fastslim import SLIM

model = SLIM(lambd=2.0, beta=2.0).fit(X)
model.recommend(X[0], k=5)
model.weights, model.n_passes, model.converged  # fitted state

fit takes any SciPy sparse matrix or array, or a dense array; values must be finite and non-negative. fastslim.metrics provides precision_at_k, recall_at_k and ndcg_at_k against a held-out sparse matrix. The full reference is in docs/api.md.

Hyperparameters

  • lambd, the L1 penalty, is compared against co-occurrence counts: item k can enter item i's model only if (X.T @ X)[i, k] >= lambd. On MovieLens-sized data useful values are single digits. Raise it for a sparser W.
  • beta, the L2 penalty, shrinks weights and conditions the problem; any beta > 0 makes the solution unique.
  • max_iter and tol stop each item once a full pass moves no weight by tol. The defaults (1000, 1e-4) converge all of MovieLens 1M. Items that run out of budget raise fastslim.ConvergenceWarning; SLIM.converged tells which ones.
  • n_threads changes speed only. The result does not depend on it.

Performance

MovieLens, 80/20 split, k=10, against implicit's ALS with 64 factors. SLIM uses lambd=2, beta=2, max_iter=50.

Dataset Model Fit time precision@10 recall@10 ndcg@10
ML-100k fastslim 0.17 s 0.3391 0.2236 0.4069
ML-100k implicit ALS 0.58 s 0.2878 0.2017 0.3433
ML-1M fastslim 2.55 s 0.3620 0.1652 0.4100
ML-1M implicit ALS 4.45 s 0.3465 0.1621 0.3915

Reproduce with uv sync --group bench and uv run python benchmarks/benchmark.py --dataset 1m --baseline als --markdown.

How it works

For every item i independently, the solver minimises

0.5 * ||x_i - X w||^2 + lambd * sum_k w_k + (beta / 2) * sum_k w_k^2
subject to  w >= 0,  w_i = 0

by non-negative coordinate descent on the Gram matrix P = X.T @ X: only neighbours with P_ik >= lambd can be non-zero, residuals are updated incrementally, and an active set is iterated until a full verification pass confirms optimality. P is accumulated in a fixed order and each item is solved by a single thread, which is what makes the output deterministic. The derivation is in docs/algorithm.md.

Development

uv sync                          # builds the extension, installs dev tools
uv run pytest -q -m "not slow"   # Python tests
cargo test                       # Rust tests

CONTRIBUTING.md covers layout, linting, benchmarks and releases; CHANGELOG.md lists what changed between versions.

License

Apache-2.0. See LICENSE.

Metadata

Release files for fastslim 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastslim 0.2.0
File Size Uploaded
fastslim-0.2.0.tar.gz 68.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fastslim 0.2.0
File
fastslim-0.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
fastslim-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
fastslim-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
fastslim-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64 Details

Total release size: 1.6 MB

Release files / fastslim-0.2.0.tar.gz

Download URL fastslim-0.2.0.tar.gz
Size 68.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a1fcfb45466d63c730ff86711d73b53dc272af8e7d017d4b4204e8795056e4ab
BLAKE2b-256 checksum
How to use checksums
b45e34ae300a4905e16f96777c4b0912bd5e7825ee01d6d93518e9a854bf5150
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / fastslim-0.2.0-cp310-abi3-win_amd64.whl

Download URL fastslim-0.2.0-cp310-abi3-win_amd64.whl
Size 221.7 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
34abff26e4e8d5785aea764936ebd19f6e51e835eb6eef674cded6cb84a8c793
BLAKE2b-256 checksum
How to use checksums
12cc59c6e15a9a2a0158f7b3cf895d84482c2fa69d3cd2ecafdbb0ff56e7c0b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / fastslim-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastslim-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 346.2 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
55fc4fc0d60b575c7889182b036e5ce08cc78c7bfe4d25067eb99cfa4b97014b
BLAKE2b-256 checksum
How to use checksums
f8f5be0326479886d26310f97730d3880cceef06c0f673c4aa13ee647ea5f0fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / fastslim-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastslim-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 339.1 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
797f8dc3e0e2dbcac288c10f553e79f3d3283d0cb6d54090f1bd453c3e73ce72
BLAKE2b-256 checksum
How to use checksums
6cf2b9af48e74e7ae724b12fc70b859127f7e9913001567c006b8c8a48e8cff4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / fastslim-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL fastslim-0.2.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 604.2 kB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
30e7522de4276dd3071b1adca7cd37cd7052a51c8c37c940c4ddcf1de03bd06f
BLAKE2b-256 checksum
How to use checksums
71466e235c5e2c96225ee1018e893c1a4c5654df0235a748ba49a7d1170d6fbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

5 release files

This release

0.2.0 This release

5 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page