Skip to main content
bispectrum_logo

bispectrum

Tests Pre-commit codecov

An open-source, fully unit-tested PyTorch library that implements selective G-bispectra for seven group actions as differentiable torch.nn.Modules, ready to plug into ML pipelines and deep learning architectures.

The G-bispectrum is a principled complete invariant of a signal — it retains all information up to the group action. Selectivity reduces cost from O(|G|²) to O(|G|) for finite groups, and from O(L³) to Θ(L²) coefficients for SO(3) on S².

Supported Groups

Module Group / Domain Output mode Complexity (selective)
CnonCn C_n on C_n selective + full O(n)
SO2onS1 SO(2) on S¹ selective + full O(n)
TorusOnTorus T^d selective + full O(n)
DnonDn D_n on D_n selective O(n)
SO2onDisk SO(2) on disk selective O(L)
SO3onS2 SO(3) on S² selective + full Θ(L²)
OctaonOcta chiral octahedral O (24 elements) selective 172 coefficients

SO2onS1 is the continuous-n limit of CnonCn and shares its implementation.

API

Every module exposes a uniform interface:

  • forward(f) — selective (default) or full bispectral invariants
  • fourier(f) — group Fourier coefficients
  • invert(beta) — signal reconstruction up to group-action indeterminacy (where available)

Modules default to O(|G|) selective coefficients; pass selective=False for the full O(|G|²) set. CG matrices, DFT kernels, and Bessel roots are precomputed as non-learnable buffers. Dependencies: PyTorch, NumPy, and torch_harmonics (for SO3onS2).

Benchmarks

Median wall-clock on a single NVIDIA H100 80 GB GPU (batch=16, torch.utils.benchmark):

Module Group |G| / L_max Coefs (sel.) Coefs (full) Fwd sel. (ms) Fwd full (ms)
CnonCn C_128 128 128 8,256 0.14 8.53
TorusOnTorus C_32 × C_32 1,024 1,024 524,800 0.07 0.31
DnonDn D_32 64 245 — 0.57 —
SO2onDisk SO(2) L=16 76 — 0.22 —
SO3onS2 SO(3) L=16 426 — 0.48 —
OctaonOcta O 24 172 — 0.68 —

Installation

pip install bispectrum

Or with uv:

uv pip install bispectrum

Apple silicon (MPS)

torch-harmonics>=0.9 publishes Linux x86_64 wheels only, so on macOS build it from source before installing bispectrum:

pip install "torch>=2.10,<2.12" numpy setuptools setuptools-scm
SETUPTOOLS_SCM_PRETEND_VERSION=0.9.2 pip install --no-build-isolation \
  "torch-harmonics @ https://github.com/NVIDIA/torch-harmonics/archive/refs/tags/v0.9.2.tar.gz"
pip install bispectrum

MPS has no float64, and the precomputed tables are float64, so move modules with module.to(device='mps', dtype=torch.float32).

Development

git clone https://github.com/geometric-intelligence/bispectrum.git
cd bispectrum
uv pip install -e ".[dev]"
pre-commit install

Pre-commit Hooks

This project uses pre-commit for code quality checks. After installing dev dependencies, the hooks run automatically on each commit.

# Run hooks on all files (useful for first-time setup or CI)
pre-commit run --all-files

# Run a specific hook
pre-commit run ruff --all-files

# Update hooks to latest versions
pre-commit autoupdate

Usage

Cyclic group on itself

from bispectrum import CnonCn

bsp = CnonCn(n=8)
f = torch.randn(4, 8)       # signal on Z/8Z
beta = bsp(f)                # shape (4, 8), complex64
f_rec = bsp.invert(beta)     # reconstructed up to cyclic shift

SO(3) on the 2-sphere

from bispectrum import SO3onS2

# Selective bispectrum: O(L²) entries with generic completeness
bsp = SO3onS2(lmax=5, nlat=64, nlon=128, selective=True)
f = torch.randn(1, 64, 128)  # signal on S²
beta = bsp(f)                 # shape (1, 35), complex64

# Full bispectrum: O(L³) entries
bsp_full = SO3onS2(lmax=5, nlat=64, nlon=128, selective=False)
beta_full = bsp_full(f)       # shape (1, 69), complex64

Octahedral group

from bispectrum import OctaonOcta

bsp = OctaonOcta()
f = torch.randn(4, 24)       # signal on O (|O| = 24)
beta = bsp(f)                 # shape (4, 172), complex64
f_rec = bsp.invert(beta)      # reconstructed up to group action

License

MIT

Metadata

Release files for bispectrum 0.4.1

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

Source distribution (sdist)

Source distribution for bispectrum 0.4.1
File Size Uploaded Provenance Actions
bispectrum-0.4.1.tar.gz 54.6 kB With provenance Details for bispectrum-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bispectrum 0.4.1
File Interpreter ABI Platform Actions
bispectrum-0.4.1-py3-none-any.whl Python 3 none any Details for bispectrum-0.4.1-py3-none-any.whl

Total release size: 115.4 kB

Release files / bispectrum-0.4.1.tar.gz

Download URL bispectrum-0.4.1.tar.gz
Size 54.6 kB
Tags Source
SHA-256 checksum
How to use checksums
42c9f19a9713aaf28bb75d820cdc91aa08407100766a4ede2cd400ac8a19407c
BLAKE2b-256 checksum
How to use checksums
af98bea735e3f56a9802f9bd5948549227dc998adadba8a0f0949a9e96f3b7af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

Release files / bispectrum-0.4.1-py3-none-any.whl

Download URL bispectrum-0.4.1-py3-none-any.whl
Size 60.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c43cdc5b05b9593056edfeacf0868c2fddba32ccf633a500f46a2285a6b6787
BLAKE2b-256 checksum
How to use checksums
416df0ae93d9a1b204f22698d2859f83ac97c6a3d6290f4740292f36c4ff5487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

Security for bispectrum 0.4.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bispectrum-0.4.1.tar.gz

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 Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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