Skip to main content

High-performance computational acceleration library for CANNS, providing optimized implementations for topological data analysis and neural network computations

Project description

canns-lib

CI PyPI version License

High-performance computational acceleration library for CANNs (Continuous Attractor Neural Networks), providing optimized Rust implementations for computationally intensive tasks in neuroscience and topological data analysis.

Overview

canns-lib is a modular library designed to provide high-performance computational backends for the CANNS Python package. It currently includes the Ripser module for topological data analysis, with plans for additional modules covering approximate nearest neighbors, dynamics computation, and other performance-critical operations.

Modules

🔬 Ripser - Topological Data Analysis

High-performance implementation of the Ripser algorithm for computing Vietoris-Rips persistence barcodes.

Performance Highlights

  • Mean speedup: 1.13x across 54 benchmarks vs ripser.py
  • 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

Performance by Category

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

Features

  • 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)
  • 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
  • Cocycle Computation: Optional computation of representative cocycles

🚀 Coming Soon

  • Dynamics: High-performance dynamics computation for neural networks
  • Spatial: Spatial indexing and queries
  • And more...

Installation

From PyPI (Recommended)

pip install canns-lib

From Source

git clone https://github.com/Routhleck/canns-lib.git
cd canns-lib
pip install maturin
maturin develop --release

Quick Start

Using the Ripser Module

import numpy as np
from canns_lib.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)

Compatibility

The ripser module maintains 100% API compatibility with ripser.py:

# These work identically
import ripser as original_ripser
from canns_lib.ripser import ripser

result1 = original_ripser.ripser(data, maxdim=2)
result2 = ripser(data, maxdim=2)

# Results are numerically identical
assert np.allclose(result1['dgms'][0], result2['dgms'][0])

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-lib.git
cd canns-lib
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

Technical Details

Ripser Module Architecture

  • Dual API paths: High-performance versions and full-featured versions with progress tracking
  • Memory optimization: Structure-of-Arrays layout, intelligent buffer reuse
  • Sparse matrix support: Efficient handling via neighbor intersection algorithms
  • Progress tracking: Built-in progress bars using tqdm when available
  • Parallel processing: Multi-threading with Rayon

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

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Citation

If you use canns-lib in your research, please cite:

@software{canns_lib,
  title={canns-lib: High-Performance Computational Acceleration Library for CANNS},
  author={He, Sichao},
  url={https://github.com/Routhleck/canns-lib},
  year={2025}
}

Acknowledgments

Ripser Module

  • 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

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

canns_lib-0.5.0.tar.gz (250.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

canns_lib-0.5.0-cp313-cp313-win_amd64.whl (279.1 kB view details)

Uploaded CPython 3.13Windows x86-64

canns_lib-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl (457.4 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

canns_lib-0.5.0-cp313-cp313-musllinux_1_2_aarch64.whl (417.2 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

canns_lib-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (392.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

canns_lib-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (365.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

canns_lib-0.5.0-cp313-cp313-macosx_11_0_arm64.whl (329.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

canns_lib-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl (367.3 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

canns_lib-0.5.0-cp312-cp312-win_amd64.whl (279.5 kB view details)

Uploaded CPython 3.12Windows x86-64

canns_lib-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl (457.8 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

canns_lib-0.5.0-cp312-cp312-musllinux_1_2_aarch64.whl (417.6 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

canns_lib-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (392.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

canns_lib-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (366.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

canns_lib-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (329.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

canns_lib-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl (367.6 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

canns_lib-0.5.0-cp311-cp311-win_amd64.whl (280.8 kB view details)

Uploaded CPython 3.11Windows x86-64

canns_lib-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl (458.9 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

canns_lib-0.5.0-cp311-cp311-musllinux_1_2_aarch64.whl (418.4 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

canns_lib-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (393.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

canns_lib-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (366.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

canns_lib-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (330.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

canns_lib-0.5.0-cp311-cp311-macosx_10_12_x86_64.whl (367.5 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

Details for the file canns_lib-0.5.0.tar.gz.

File metadata

  • Download URL: canns_lib-0.5.0.tar.gz
  • Upload date:
  • Size: 250.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for canns_lib-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fdf6a6b86551a28f2b36b84dba59dcfcb6220e1289093238864a90742d37c0ca
MD5 eecc4dde521aa98b5f5ee0e88ce2d8cd
BLAKE2b-256 a05362d47246c7c0eab2407ffe1f9536131794ece3672fc691881bcc164cb9eb

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: canns_lib-0.5.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 279.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4201f335889b2822f318f6d5604dcea9191bdd99f1765de58db099b226fca989
MD5 2f065951ea5f0303960351e8be8bf9a2
BLAKE2b-256 70a77f9d22453c3cd28272e6d3161c4be72760e4e16db9b100e722dd67e255e9

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f643308bb81423b9e837de0c19a247d14a4ca120e6d6e65ad1eabae773ae284b
MD5 a09855108234be8f30e6623b1d017f04
BLAKE2b-256 b5814fc1e7ba72f72f76b003d03755281e4491c07bf9f7f680d94f072c7369e9

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c519c5e8af6193202d7dab283f2beb95bd520c7a6bbdae0a198eded4615c0bfd
MD5 355b9b9799b1734b96a2333775cb3143
BLAKE2b-256 c81c368db91416d9186132f5e993eb21075f8d7e04310a2e1b769d7df076edf9

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c351dc838b37036763463a6f6e1ffe54c3082046a7384eac86c8d4f84c17e3ed
MD5 3fa40954ce4b2a258713fe3b94038a64
BLAKE2b-256 9799f950fbca74e3c0e6459f16a660bee0eff61467d97d7dc4b43511dd1dfad5

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ec47c5b211e4365c23513b004fa096e4304653f7d148b8c911ac1388cff2fdc3
MD5 7afbb67a9d409cc643ea38fcadf9d572
BLAKE2b-256 74b0221b9ddb576df14970d1ca1831b4b5ae2723d8335c70e86b061d9597f245

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48528bce067890702053a05d7b22875467b18e584a6b73156a99b3bdc6ea53e1
MD5 7f261d4da0e604625d731033d2c44eb2
BLAKE2b-256 a6683c99547966fa43c28dcc5dd3e93a064c8ae748fb1a4098e6e0c31acc9c93

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 376687749d614689e874a84a828e744ee059c2bc5ab93494e87bf82a916f7367
MD5 e4d6923c0d8fb7c383f7e589ad1a05a7
BLAKE2b-256 3bc0ee47698c40bab03fca1dbf32cdeb3dc05c9f16ce71d6f99d5b207338c481

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: canns_lib-0.5.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 279.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0cb8df8f1ad9c9f8975602fff8626514345cf1c85abbaf16498704bf6464107c
MD5 1935b98033143f1e0561b824fa0507be
BLAKE2b-256 a572a4d7d11f14d97a1d129e29bc3ab032728b1bb6243c48cc8aecfe53c6c5ad

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9eae771650f19266d7dc615aed10ff91387d9973559414026119779717175eb2
MD5 9fedcc35213a4c2fc8c3bdaa533f2839
BLAKE2b-256 f4698fa5a3d37ae8ed972fb61c4396fb1710f7033c6acb8ef830b2e06cb3cf18

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b1f2897481418a917ee5cc0b982971198bfc0b4a328f05f57f5bd4c8187b9944
MD5 e0335d0ed907a1b494def02d04257506
BLAKE2b-256 1c73624d94d65ce8733ada84c31651bd7b77d5fe806c21c55e7ec2449d4fe905

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ea719e351153b0d16fc8bc2064541e0af4b1d9bf1545ddb3f787495b6e53212
MD5 572ee7021ad6ee2ba4dd89a1dad8fd6f
BLAKE2b-256 f72056a36e91b3b9033a543bff38264739577350962a3bda437e31a09e110a32

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4091ff6f1bd4037ca1c84a7230a53d994cec6e3972ad1921fb6c2caf16227c2f
MD5 f11dd2b43c9b38398b33536f4fd42803
BLAKE2b-256 481518dae3e931d2dbaef8a903ab390d20408c5e457ab6aa74ca739ffc5bdb4a

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 93a513f3e3646fead44a3f60cd586b54219afb06884b8eac7d7a9c54b4c3c2cb
MD5 0a6bd2375098f0cf8a4ae65c70880695
BLAKE2b-256 d7e8f10f60526515b9425632f31766a53cdbb54ded488e53bf0daf060bfc0c85

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 8291a91fd8e69e55b925cb1ec714e70117e0f1d0c3fe1685a4451ba039170072
MD5 5a377fab6503d826b424a15fffe1ae80
BLAKE2b-256 86dab66e144b39ad996d1c931f115373cbc8e0ae4fe4c31299ccc88261150dfe

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: canns_lib-0.5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 280.8 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c976cbb5e6d6b7ce4e7b5cf67dbf656fbdebb974f8432131af70232e66804a2a
MD5 86a2ec5a765a3313239bd4765e463158
BLAKE2b-256 8f60b0a35f66f87203c9000d6ce8d1c02e6d164ade66f925b2bb7eb0313c9984

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8798e42c5d53a3e08aed57e57900fcdc54f383be9474c5421a6adc7da80a36b6
MD5 25d74bec79431403deabc07aa45b27a4
BLAKE2b-256 92e9ec6a7b4cad04c4e69159370a159d2e1e38ce4dcff88c833ec19aff12f5cf

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4f337e1c9eac96f9ea05410ec4988f1b20a5fd837d9503f3de875c87345f9a6f
MD5 1d33f0982fb4bd2291360bfa6e54f8d9
BLAKE2b-256 4ba1e6e6cbec7f7005c3a939982beb8c966ed6e0189dd26b9cd2bc127fcb7e05

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bef7d96761b78e2021aca99da81cd337664a8518d6b5ccafae1663fc972a2824
MD5 182beb7ee34af487b5e1ba8d8aefe227
BLAKE2b-256 c8441b60c4a356c47e39aca02864019878a43bac097fb55d8f51a6ed3e409a1b

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6bccc511e1d098345b4fa09ca037c69c32d81b9e3a8644fb41168e1e24a26cd5
MD5 27109b1e8ed124fdc573f85f576bbbac
BLAKE2b-256 49b73b81d12112f88b441e5d7be77b127fca4aa80a48981636752e1ee1c76016

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c7fdfe148510d24dadc3d34d0a2379b91ad3f5c0be65205a419b33a78f95abda
MD5 4feb77f00a2d291110b3310f32850faa
BLAKE2b-256 24c86a87325ed8e7225fc055221a0c4aa94779d11f29ca9c5143d4e72069d445

See more details on using hashes here.

File details

Details for the file canns_lib-0.5.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for canns_lib-0.5.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 11c16b271800714ae45ce7f15c15b9eee0fa89ee94008fc1bb36a1dc2880a0f6
MD5 d82d666bc2784b5accdeac4e91e8d071
BLAKE2b-256 f4f912e008f754054b80f4b3d9b1abf29f395c9c5211228886cd28c06d5daef0

See more details on using hashes here.

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