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.6.0.tar.gz (276.1 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.6.0-cp313-cp313-win_amd64.whl (374.9 kB view details)

Uploaded CPython 3.13Windows x86-64

canns_lib-0.6.0-cp313-cp313-musllinux_1_2_x86_64.whl (562.7 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

canns_lib-0.6.0-cp313-cp313-musllinux_1_2_aarch64.whl (509.4 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

canns_lib-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (496.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

canns_lib-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (457.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

canns_lib-0.6.0-cp313-cp313-macosx_11_0_arm64.whl (416.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

canns_lib-0.6.0-cp313-cp313-macosx_10_13_x86_64.whl (464.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

canns_lib-0.6.0-cp312-cp312-win_amd64.whl (375.3 kB view details)

Uploaded CPython 3.12Windows x86-64

canns_lib-0.6.0-cp312-cp312-musllinux_1_2_x86_64.whl (563.2 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

canns_lib-0.6.0-cp312-cp312-musllinux_1_2_aarch64.whl (510.0 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

canns_lib-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (496.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

canns_lib-0.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (458.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

canns_lib-0.6.0-cp312-cp312-macosx_11_0_arm64.whl (416.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

canns_lib-0.6.0-cp312-cp312-macosx_10_13_x86_64.whl (465.2 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

canns_lib-0.6.0-cp311-cp311-win_amd64.whl (377.4 kB view details)

Uploaded CPython 3.11Windows x86-64

canns_lib-0.6.0-cp311-cp311-musllinux_1_2_x86_64.whl (565.2 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

canns_lib-0.6.0-cp311-cp311-musllinux_1_2_aarch64.whl (512.5 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

canns_lib-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (498.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

canns_lib-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (460.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

canns_lib-0.6.0-cp311-cp311-macosx_11_0_arm64.whl (417.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

canns_lib-0.6.0-cp311-cp311-macosx_10_12_x86_64.whl (465.9 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: canns_lib-0.6.0.tar.gz
  • Upload date:
  • Size: 276.1 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.6.0.tar.gz
Algorithm Hash digest
SHA256 ca6fc05de72464ea6b1560003f369faa68134c949a6836fb4c9fa5ebd46340be
MD5 791553aff897d79b4a902fd438907e2c
BLAKE2b-256 8fedc1f27c01ed51509ddde01e6c7f45b5805217cb9f844e09b19a657eec159a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canns_lib-0.6.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 374.9 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.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ba4c06e1e300d51141287ac424378e25e74e64722d574a48a2c3cdde9bf10371
MD5 ea583be1f22869c3acc8135b1b2ad786
BLAKE2b-256 90583078c5f51f0e0a4a17f09d056fcc1c108daf9856cd80e0e19485258bce44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7b512f046f41eb593b0b381eecc7bf9c19e49f5b82535fd7384ce39792909571
MD5 69ba7eea01f174f98cb6a146b90716e2
BLAKE2b-256 254936f9ad58806f8d95f214b09d80e3d05ed64d2aa2c50a3bff75036be23082

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 69aa8863b84a91ab9b407f89f3276cd5a261f668356731e0fac97d408f16469e
MD5 85c3fe948f769070f4b330f503bd39e3
BLAKE2b-256 954d85855cf9ce214e5c0cf0367a2a35e04829b43b8c4d9bc99522bc919bba1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 087866e7e69945465796c1321cc7970d500f57ab84ff4102e6f0306672b50989
MD5 edfe7b40932b421032941cca63708f16
BLAKE2b-256 ed9b9570d16c8d99dd9c0af9a414aa2c52e8eff120bd42d0cfa84a920d965fe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0d49556030160e48c900390a86a122f2fc815c03435dbfbf539843bf9a1c4ce6
MD5 d15a0034344f787c3c66e0b0f32b04f8
BLAKE2b-256 008ce9575d9d2f8597fccabdc4997592cfea6d0b9c6ea4d1ad9fda6b6392f229

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0e6362d5acfcd4bad51549bdc7927905159fcb2788f70e67bdafc82b8f13f50
MD5 d55e4763227822b47b57cc132ef703dc
BLAKE2b-256 72d612c3e669cf64f3037f82e05617545d1111cae9b374e38db98cd79604a9cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 771044e43e18377e3bb633687540ef275175b0ca5e3030e830bd2a7560c1dd19
MD5 d5f4e26f04d8796ad9fba14495429bec
BLAKE2b-256 312f993fa4ffb80cb8d28cf2b8ed551515e9960e2de8d8138a8577955567f881

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canns_lib-0.6.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 375.3 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.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9ff14cc21221ce35c63417a8c8a2d07a20b3aa3d1e5b284291b10683422d17ea
MD5 c501b8b41bbe82954d2e3caadd826bcb
BLAKE2b-256 f0b9d42ef666e16b597ef293cd325ed1a572decee15299bc0795b7717ede020d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 52565d6f135b6084d179160c68efc6964ad3b9948b55ea11eb373ab6b90f9075
MD5 a2fd77930a86cb0c559f97aaded737e3
BLAKE2b-256 ec4d3e7471a87ba0ae0262f5010f9a3f7351aeec002a177225c7a1e6be45e171

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1d5209235758367815221e15978c850c18678e9beb03db662417c2ce44dee8fe
MD5 4b019ea8482cf754378d2159ee952f89
BLAKE2b-256 2a643e911da4b3e10b2a4ca4f6a63944ae7700fdb0bd5947291a628ac35d0988

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72328f4bc5564e63d08102506c5b27f2f3141a81def06d907f0591644a9c3fcd
MD5 7bb14a7fd33233746684ec73d770d4b0
BLAKE2b-256 e19f993ef587b698ac43b2fee7b8776462ebb79fcc3b3aa031dd8e030ef746a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 75632e4c74167b1a4f88b7f733875562b9c4d75a4097c5de75402cfd2e6e50b6
MD5 409b91c326dfaa568d41188acc5f5b95
BLAKE2b-256 55bc6c3897c861f8e6aa2b3e8f680950c18119520dd0551c875812768e41a4a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9fb4b06a7e2137bbdaf88ffe059f525aa314b3b06b223cb7e1799feb908c117
MD5 741c3df9ec90e0465558e16eed37a49c
BLAKE2b-256 b11411edd1be8d145ff5a59a2b04f084d39c8727932e3430a60c6d1e238001da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 785a4ae24b9aa7d7d4bdf23130d96b58cf39454803ed657f38f1fb7f9c77e992
MD5 27c726b5b1862c7c0afb4bbfc85f26c5
BLAKE2b-256 3e7884a803ca7521195a9a886c0ee8bb6025c28ad567934226013b677ddca778

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canns_lib-0.6.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 377.4 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.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0b820316eca4f797725c07edb504c265bd59c4ae9dd5ad36bd8190bcd3f3e335
MD5 ad88e231d55f1fe8857086d90a384d72
BLAKE2b-256 6f8b0b565681524a17e847196ce51d84e141d16f9e14b2dee3d5417dd41ef57f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bf44d7be0bcd92d61fc3fd38fd99070585fbf9b10ac5d919c23548066ee41beb
MD5 1a96b0b5def1f805e421eeb7d9875b12
BLAKE2b-256 7ae6b8b5d047a64cfd8cc35230923b035f00ee05baedc832e64e459efba7c46b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 83aa81e096d2d17833e80a35990c66b89a08d53f2da15cc201b366269dae3a89
MD5 9b89879cb63e5ee8d7efe77780ed63c1
BLAKE2b-256 a080e88b7de68eeee488178c115167bddeb740af9867c4b4c795e98b9c64415e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b545824fb1c755e9226c9c9649610d741b5a5bf272d44696d3d0cb326e1c397
MD5 b89e95e570cdc751a4f86531fe80f2c1
BLAKE2b-256 34876468eb94e1f91316782b4ef2ed94a1e930414da6248038159183baf99d35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a9226fc1dd78aa2549202c3c9a3d36f645f6e46c41a7182a24cf4685fcfa4446
MD5 f83eef310b5c82897eec7282a2e9c7c3
BLAKE2b-256 ea3187ddfb5a78ce741cef9d174b5bc3606f7fc43d2311f832c0396f7c047912

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb2c9c5e3fd9855d79b8db7f2c0073904dcb0b1a168795da2b7eabe8e00aebf7
MD5 af4cfe537dd40c412d38cef55d6b6d27
BLAKE2b-256 f1479fcb18a024f2d564461062891e1a9b25050e983aa55739da2e6078d2e80c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for canns_lib-0.6.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 42d595c806c0435f346baee49deace2ee0aac4adcfc10bde027298dba9f2ed4b
MD5 9bf1da4e1f2e9a90067c54e23332a215
BLAKE2b-256 c63e806e061105cf9aeff5c898ed246543c569bd2750e234efce5d0ba6bef2bc

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