CANNs-Ripser
High-performance Rust implementation of Ripser for topological data analysis, optimized for the CANNS library.
🚀 Performance Highlights
CANNs-Ripser delivers significant performance improvements over the original ripser.py:
- Mean speedup: 1.13x across 54 benchmarks
- Peak speedup: Up to 1.82x on certain datasets
- Memory efficiency: 1.01x memory ratio (stable usage)
- Perfect accuracy: 100% match with ripser.py results
Top Performing Scenarios
| Dataset Type | Configuration | Speedup |
|---|---|---|
| Random N(0,I) | d=2, n=500, maxdim=2 | 1.82x |
| Two moons | n=400, noise=0.08, maxdim=2 | 1.77x |
| Random N(0,I) | d=2, n=200, maxdim=2 | 1.72x |
| Random N(0,I) | d=3, n=500, maxdim=2 | 1.72x |
| Random N(0,I) | d=3, n=200, maxdim=2 | 1.66x |
Overview
CANNs-Ripser is a high-performance Rust implementation of the Ripser algorithm for computing Vietoris-Rips persistence barcodes. It provides a Python interface that's fully compatible with the original ripser.py package, making it a drop-in replacement with significantly improved performance.
Features
🔥 Performance Optimizations (v0.4.0)
- Algorithmic improvements: Row-by-row edge generation, binary search for sparse matrices
- Memory optimization: Structure-of-Arrays layout, intelligent buffer reuse
- Parallel processing: Multi-threading with Rayon (enabled by default)
- Cache efficiency: K-major binomial coefficient layout, aggressive inlining
- Zero-copy operations: Minimized allocations in hot paths
🔧 Core Features
- Full Compatibility: Drop-in replacement for ripser.py with identical API
- Multiple Metrics: Support for Euclidean, Manhattan, Cosine, and custom distance metrics
- Sparse Matrices: Efficient handling of sparse distance matrices with neighbor intersection algorithms
- Cocycle Computation: Optional computation of representative cocycles
- Progress Tracking: Built-in progress bars and verbose output
- CANNs Integration: Optimized for use with the CANNs Python Library for Continuous Attractor Neural Networks
Installation
From PyPI (Recommended)
pip install canns-ripser
From Source
git clone https://github.com/Routhleck/canns-ripser.git
cd canns-ripser
pip install maturin
maturin develop --release
Quick Start
Basic Usage
import numpy as np
from canns_ripser import ripser
# Generate sample data
data = np.random.rand(100, 3)
# Compute persistence diagrams
result = ripser(data, maxdim=2)
diagrams = result['dgms']
print(f"H0: {len(diagrams[0])} features")
print(f"H1: {len(diagrams[1])} features")
print(f"H2: {len(diagrams[2])} features")
Advanced Options
# High-performance computation with progress tracking
result = ripser(
data,
maxdim=2,
thresh=1.0, # Distance threshold
coeff=2, # Coefficient field Z/2Z
do_cocycles=True, # Compute representative cycles
verbose=True, # Detailed output
progress_bar=True, # Show progress
progress_update_interval=1.0 # Update every second
)
# Access results
diagrams = result['dgms'] # Persistence diagrams
cocycles = result['cocycles'] # Representative cocycles
num_edges = result['num_edges'] # Number of edges in complex
Sparse Matrix Support
from scipy import sparse
# Create sparse distance matrix
row = [0, 1, 2]
col = [1, 2, 0]
data = [1.0, 1.5, 2.0]
sparse_dm = sparse.coo_matrix((data, (row, col)), shape=(3, 3))
# Compute with sparse matrix (automatically detected)
result = ripser(sparse_dm, distance_matrix=True, maxdim=1)
Performance Guide
When to Expect Best Performance
- Medium to large datasets (n > 200 points)
- Higher-dimensional homology (maxdim ≥ 2)
- Moderately dense point clouds (not extremely sparse)
- Random or structured data (vs. adversarial/pathological cases)
Optimization Tips
# Enable all performance features
result = ripser(
data,
maxdim=2,
thresh=2.0, # Set reasonable threshold to limit complex size
coeff=2, # Z/2Z is fastest (default)
progress_bar=False # Disable for batch processing
)
Compatibility
CANNs-Ripser maintains 100% API compatibility with ripser.py:
# These work identically
import ripser # Original
from canns_ripser import ripser as ripser_fast # CANNS-Ripser
result1 = ripser.ripser(data, maxdim=2)
result2 = ripser_fast(data, maxdim=2)
# Results are numerically identical
assert np.allclose(result1['dgms'][0], result2['dgms'][0])
Technical Details
Algorithmic Optimizations
- Dense edge enumeration: O(n²) row-by-row generation vs O(n³) vertex decoding
- Sparse queries: O(log k) binary search vs O(k) linear scan
- Cache-friendly data structures: SoA matrix layout, k-major binomial tables
- Zero-apparent pairs: Skip redundant column reductions in higher dimensions
Implementation Features
- Memory allocator: mimalloc for efficient small allocations
- Compilation: Link-time optimization, target-specific vectorization
- Parallel execution: Rayon-based work-stealing parallelism
- Error handling: Comprehensive validation with helpful error messages
Development
Building from Source
# Prerequisites
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
pip install maturin
# Build and install
git clone https://github.com/Routhleck/canns-ripser.git
cd canns-ripser
maturin develop --release --features parallel
# Run tests
python -m pytest tests/ -v
Running Benchmarks
cd benchmarks
python compare_ripser.py --n-points 100 --maxdim 2 --trials 5
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Citation
If you use CANNS-Ripser in your research, please cite:
@software{canns_ripser,
title={CANNS-Ripser: High-Performance Rust Implementation of Ripser},
author={He, Sichao},
url={https://github.com/Routhleck/canns-ripser},
year={2025}
}
Acknowledgments
- Ulrich Bauer: Original Ripser algorithm and C++ implementation
- Christopher Tralie & Nathaniel Saul: ripser.py Python implementation
- Rust community: Amazing ecosystem of high-performance libraries
Related Projects
- Ripser: Original C++ implementation
- ripser.py: Python bindings for Ripser
- CANNS: Continuous Attractor Neural Networks
- scikit-tda: Topological Data Analysis in Python
Release files for canns-ripser 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| canns_ripser-0.4.4.tar.gz | 246.3 kB | Details |
Built distributions (wheels)
Total release size: 7.6 MB
Release files / canns_ripser-0.4.4.tar.gz
| Download URL | canns_ripser-0.4.4.tar.gz |
|---|---|
| Size | 246.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
747ea54bbef6799f5283e9014ac45610f799baf4f84bc800af798a35a532893a
|
|
BLAKE2b-256 checksum How to use checksums |
8627df0a5e879177acced320d4722d458ae51bdc4176116f33bc3d012eb95d0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-win_amd64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 257.2 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1e0f7efece906055b71729a4265782bdf61a09436d893ef36f4006735bdb182f
|
|
BLAKE2b-256 checksum How to use checksums |
3a1887c7fa76c55f9a516a556a9a4bad508c353961bc2bb933e8722e09a03cfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 434.2 kB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
df6fb0bbf6257843276afd0d228c1e7063ccc0f8d256e56b7be4462b4a4e354e
|
|
BLAKE2b-256 checksum How to use checksums |
7771220be081f9fd6e9f754c77f764b441516121978c02f21c3727e650ad83dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-musllinux_1_2_aarch64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 397.5 kB |
| Tags | CPython 3.13 Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
e2b5f5611a36a171f48dcb5d7bf7c4ffe1400cdc97f2e7a1bef5133397360dd7
|
|
BLAKE2b-256 checksum How to use checksums |
15c92b3b39127b2e12453abfac5f7d1776419f0bb4776b72fa8f234b6758a137
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 370.7 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
fa1b40213e44c4269678e8f6e95cf26271ddbbee62a0010e855b2a49778e302e
|
|
BLAKE2b-256 checksum How to use checksums |
3cf9f6c92c34022aa7c862c403e48686b829a2298647aad4c828ff67ea3d2c07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 346.6 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
ae6ee240d29051c4fba926ada33161997b10cbaf60646efe124077e3e59b08c5
|
|
BLAKE2b-256 checksum How to use checksums |
3bb32487654002bd0b264bc7f24b5a192448e14cfc9fe9a7e3ab5c3dd25c14bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 309.6 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
932290d62c5dae0a2b7571c54b2c7385f1e5e2c5251387db9411a2f0a1b80054
|
|
BLAKE2b-256 checksum How to use checksums |
b45c7e8ef2040301809a64e6344d675050d0017b20349c338bcd756c2acbb606
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 344.1 kB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
0f5cbd8aa36d57913fa5e47b764db116cfbb2a74415dd17cf8bfd88991ad8549
|
|
BLAKE2b-256 checksum How to use checksums |
e5bd3fedeca67b2787ed94758e4cc50c60c749f77a975072357c4f271b86d4c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-win_amd64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 257.5 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a908fdcee3f5e87d154bf87c3c14c504e9532fea07a375e2c3d8e1faa3a12dab
|
|
BLAKE2b-256 checksum How to use checksums |
c7fa116cb56631678b6aeb21ee027f5b66273a7e4d77a49986d8b1bb161a6ae9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 434.5 kB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
dbe341e775bfd3d46f70b58cb689c6456455d973dc0dec83a157ef71dcdbc8a2
|
|
BLAKE2b-256 checksum How to use checksums |
4387b574cc29c7170138f1cc0e3e255cfb8120a5ff639d394095bb7a968a7f95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-musllinux_1_2_aarch64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 397.6 kB |
| Tags | CPython 3.12 Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
c0ca471b67feddff6fea39c230c8d774728faf7ee527361a5f68d8d182603fe1
|
|
BLAKE2b-256 checksum How to use checksums |
13beb78809ca534790fb9f1d4acde4ddcb59b748818a586b2e4e72dddc4a5aac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 371.1 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
ea2e2c5f82d3555642d2c63297b3a194d7fe37fc1ac551d6df540561dd44d450
|
|
BLAKE2b-256 checksum How to use checksums |
51463c5d61a9b09413df555f6d79b7d03aa64b414ff828d1e8cbf53edfe9901a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 346.8 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
7f1e780eb440b549ea7684b45337c4e01db118054f143b374d566912ba7fd3b8
|
|
BLAKE2b-256 checksum How to use checksums |
0d122d8c17357875c0db809a327dd1de3c92c6d5615e6786ea3283be959f63c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 309.6 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8ea964cff00f70a2d7bb282543e0bf69d9449f547e16ccd1ef2c79ede0c44900
|
|
BLAKE2b-256 checksum How to use checksums |
e9c9e6bf6aacfd05dda69c8cedff2786057e274cab4fd426ebb746090150475a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 344.4 kB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
ce58ea1bf30b4a96de0f80c0dbf5f51db76114d94bc5682b6d9bb653a486d30c
|
|
BLAKE2b-256 checksum How to use checksums |
b5839b2bd7a5c0c076ccebd0619a10037c84d129b489b92bef4b9528c9ca2780
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-win_amd64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 258.8 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
43e74e248365237d26e26c873303a81ae09f9ffc6c5e179cab977e12e2469233
|
|
BLAKE2b-256 checksum How to use checksums |
47744d11260170f3a469afb858fb973c2675fd3835fcaf390cc8629adbec14d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-musllinux_1_2_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 435.3 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
4b419b9ca9bc95a55716b7557fbd875433dbc5e3c421c8b380def9d646dfcffc
|
|
BLAKE2b-256 checksum How to use checksums |
fa3b86b87898f6f443f7f4e0096bed41fbd9490605dfc4a37cd09cb3cc0db192
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-musllinux_1_2_aarch64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 399.2 kB |
| Tags | CPython 3.11 Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
2d175f0eb65f1f67d303047c8ef00b2e2502cd04ad8b8ab8a5078b5a54dd5b1f
|
|
BLAKE2b-256 checksum How to use checksums |
4165024ac6a517bff8bcd2aa8a2c32311474fbfcdbab29fec8ad3fd557b9c974
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 371.8 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
278b680383cb0c890ccc98144c46a5c887c0830db001c5fd29037dd1e7e8d0e5
|
|
BLAKE2b-256 checksum How to use checksums |
5f7551bb3f8b2e710fed73e13b39ad63634ddb28f8c11c84ce2c22ad82eb5aee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 348.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
9971eaac0e93dfeeb479dd978731da875d8fbb59a8fb075ced417d10dd707eb8
|
|
BLAKE2b-256 checksum How to use checksums |
7ea47ffeaa6e87bcc084020c98f2aafbc9a202476abece67eedfee164299600b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 311.2 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
aa7d73afa4b212dbafe65af9eced7eee04db0aafea20096f77aeb6ddc4e62725
|
|
BLAKE2b-256 checksum How to use checksums |
d7817316ac8d7b85137a2757c9c682d2a01094be4bb176a77da61fe9c3ecc2ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / canns_ripser-0.4.4-cp311-cp311-macosx_10_12_x86_64.whl
| Download URL | canns_ripser-0.4.4-cp311-cp311-macosx_10_12_x86_64.whl |
|---|---|
| Size | 346.2 kB |
| Tags | CPython 3.11 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
73fd0a9711874ab87b880fdbdfaff53c15fc92b7375e635d6d6050cba56c84b9
|
|
BLAKE2b-256 checksum How to use checksums |
ad54510effb2d790d8bc3a1a44b34cdcced58d6bc8175aec0964d1ddd148136b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|