Skip to main content

Topp 标志

Topp

用于 persistence diagram 的 exact Bottleneck 与 Wasserstein 距离。

CI status PyPI version Python versions

English · 网站 · 使用说明 · API · 数学约定 · 开发指南 · 更新日志

Topp 面向已经拥有 persistence diagrams,需要在 Python 中做严格、重复距离比较的用户。它提供小型 Python API 和自适应 C++20 内核;对同一个 diagram 执行多次比较时,可预处理一次并直接调用原生批量接口。

v1.0.1 稳定版: 本页记录的 Python API 进入 1.x 兼容性范围。C++ 头文件与 ABI 仍是内核维护接口,不属于稳定性承诺。

适合什么场景

选择 Topp,如果你:

  • 已经从 GUDHI、Ripser 或其他流程获得 persistence diagrams,只需要计算它们之间的距离;
  • 需要 exact Bottleneck、W1-L∞ 或 W2-L2,不希望近似参数改变阈值判断;
  • 会用一个查询图反复比较许多候选图,希望复用预处理结果、workspace 或输出数组;
  • 希望运行时只引入 NumPy,并使用带类型信息的 Python API。

Topp 不负责生成 persistence diagrams,也不提供任意 (order, internal_p)、近似/GPU 距离或完整 TDA 工作流。需要这些能力时,应继续使用覆盖面更广的 TDA 库。公开文档提供了 Topp、GUDHI 与 Hera 的 Python 批量距离速度表;结果仅代表表中固定环境和调用方式。

提供的能力

  • exact Bottleneck Distance(点间使用 L∞);
  • exact W1-L∞ 与 W2-L2 Wasserstein Distance;
  • 不可变的 PreparedDiagram 和原生 one-to-many 计算;
  • 支持复用输出数组,以及 exact bottleneck_within 阈值判断;
  • 原生计算期间释放 GIL;
  • Windows x64 与 Linux x86_64 的 CPython 3.10–3.14 wheels;
  • 运行时仅依赖 NumPy;AVX2 在运行时检测,不要求所有机器支持。

安装

py -m pip install topp

预编译 wheel 面向 Windows x64 与 Linux x86_64。macOS 可尝试使用 CMake 3.24+ 和 C++20 编译器从 sdist 构建,但尚未纳入 CI,不属于已验证平台。

快速开始

import numpy as np
import topp

x = np.array([[0.0, 1.0], [0.3, 0.8]])
y = np.array([[0.0, 1.1], [0.4, 0.9]])

print(topp.bottleneck_distance(x, y))
print(topp.wasserstein_distance(x, y, order=2, internal_p=2))

query = topp.prepare_diagram(x)
print(topp.bottleneck_distances(query, [y, np.empty((0, 2))]))
print(topp.bottleneck_within(query, y, 0.1))

完整示例见 examples/basic.py。

批量比较并复用内存

targets = [y, np.empty((0, 2))]
out = np.empty(len(targets), dtype=np.float64)

query = topp.prepare_diagram(x)
topp.wasserstein_distances(
    query, targets, order=2, internal_p=2, out=out
)

支持的度量

函数 语义 状态
bottleneck_distance exact Bottleneck,内部 L∞ 支持
wasserstein_distance(..., order=1, internal_p=np.inf) exact W1-L∞ 支持
wasserstein_distance(..., order=2, internal_p=2) exact W2-L2 支持
其他 Wasserstein 参数 数学上可能合法 NotImplementedError

输入契约

输入必须由 Python/NumPy 实数、Decimal 或 Fraction 组成,并可转换为 (n, 2) 的 float64 数组。复数、MaskedArray、布尔值、数字字符串和超出 float64 范围的有限值会被拒绝。空图、对角点、重复点和规范 essential points 合法;NaN、birth > death、birth=+inf、death=-inf 及其他非法无穷组合会抛出 ValueError,不会被静默修正。

距离定义、对角线代价、重复点和 essential points 的处理见数学约定;调用契约见 API 文档。

内核维护边界

C++ 源码保留候选生成、图表示、matching、component 和 incremental pricing 等显式策略,用于回归、消融和维护。它们不会暴露到普通 Python API,也不代表默认性能承诺。1.0 默认路径、保留基准和已淘汰路线见内核最终状态。

开发

py -m pip install -v .
py -m pytest tests/python
cmd.exe /d /c scripts\build-kernel.cmd

现有 include/bottleneck/* C++ 接口用于社区维护和内核实验,不承诺稳定 ABI。构建、测试和 benchmark 约定见 开发指南。

项目导航

入口 内容
项目网站 适用场景、安装、API 与数学语义概览
使用说明 安装、单次与批量调用、输出数组和异常处理
API 文档 完整公开 API 与输入契约
数学约定 距离定义、对角线、重复点与 essential points
开发指南 本地构建、测试与 benchmark
贡献指南 正确性和性能修改的提交要求
研究记录 1.0 最终状态、内核实验和差分证据
更新日志 版本能力与已知限制

引用

研究中使用 Topp 时,请引用仓库版本与发布标签。机器可读元数据见 CITATION.cff。

许可

Topp 使用 MIT License。GUDHI 仅作为测试 oracle、语义参考及历史补丁来源,不是运行时依赖;详情见 第三方声明。

Metadata

Release files for topp 1.0.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 topp 1.0.1
File Size Uploaded
topp-1.0.1.tar.gz 183.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for topp 1.0.1
File
topp-1.0.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
topp-1.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
topp-1.0.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
topp-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
topp-1.0.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
topp-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
topp-1.0.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
topp-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
topp-1.0.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
topp-1.0.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details

Total release size: 4.2 MB

Release files / topp-1.0.1.tar.gz

Download URL topp-1.0.1.tar.gz
Size 183.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bf346a88362b550ff155109b6e65fb87beaadd81fd4c42971768fe314e7bc0bb
BLAKE2b-256 checksum
How to use checksums
62f05a7dd166f9e006ca5ebcc3223fc4ef10ab488a0a81a54129033ceae4fec5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp314-cp314-win_amd64.whl

Download URL topp-1.0.1-cp314-cp314-win_amd64.whl
Size 456.8 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
947023ee92dff4d1fd2110c7ab01a7b2905e259a45062713d3eaf1aa2758e9e4
BLAKE2b-256 checksum
How to use checksums
5f0af96d66fd648ff5c961e040493ff4a536e9ec5c67e38b4342d6c11bb9bd90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL topp-1.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 350.9 kB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4e93f1dcdff612f84edd4fb4bcb00786625f22dc21da96fbe944600ac3012482
BLAKE2b-256 checksum
How to use checksums
c4deff0cb28dc2da6b1755c8b76f1b16b7612a01f23f7d8cf9389c147be18eba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp313-cp313-win_amd64.whl

Download URL topp-1.0.1-cp313-cp313-win_amd64.whl
Size 443.0 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
40fa579198c56187e4c106e6b1037f848bc71363085c9aaefe69a4a0d35f8025
BLAKE2b-256 checksum
How to use checksums
645f84d132b9c14d62402e318856b8a213f652973ba7540f95ce2cc1dfb129ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL topp-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 350.8 kB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1909b1c6b8b0944225b7dbd3da80aac4bc7ad9137f4142110f6ed759bf47f49e
BLAKE2b-256 checksum
How to use checksums
90e2d523f8a221d26f7bfe36bef1c85a4a4ad3aaf6275885db23fd122af9d06f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp312-cp312-win_amd64.whl

Download URL topp-1.0.1-cp312-cp312-win_amd64.whl
Size 442.9 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
24a73c625fe4b2d36351a284db5df8d97f47c03cf7ca8074ccdfeea97404ec3e
BLAKE2b-256 checksum
How to use checksums
fcaaa872633ea927682a473caac9b12c1242bf3c85da2928cf01105e1fa0c99b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL topp-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 350.8 kB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
109910392fee2205755c504c23aef033471f7d6c505310611a076162944a1726
BLAKE2b-256 checksum
How to use checksums
ebc4b1f888b48d3b935b797983413148ec15ef3e4c61e5476484913951105fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp311-cp311-win_amd64.whl

Download URL topp-1.0.1-cp311-cp311-win_amd64.whl
Size 441.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
be2c1946fc62ed6113fca2a8c8b610f9887b3f6fb6872360c6a14ac5ab1e2664
BLAKE2b-256 checksum
How to use checksums
ba87e4ff1dc3f80214fb10da344f12b0f1a651db356a06206a192590988db0e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL topp-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 349.2 kB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
38a3858e5fe63f2f46660f01a0fe61599957542f2d9e10c1d599d8e08bda0dfb
BLAKE2b-256 checksum
How to use checksums
ad06b17e2f1fefbe507b4b0d85d973935dd0a46523eb6e82658ab83c3c57a0f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp310-cp310-win_amd64.whl

Download URL topp-1.0.1-cp310-cp310-win_amd64.whl
Size 440.5 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
e188ed0dbc697144d4105843fead88df02143537ebf7a84c21f6ea9470caa0f2
BLAKE2b-256 checksum
How to use checksums
456585c0b80aadf2f50614294eb47013d15b9feb2dd174e039f0b06275835ae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / topp-1.0.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL topp-1.0.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 348.0 kB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
750174a34222ae2011685bc64ba419d4e9687e456c1b0c45ade10f1505e159aa
BLAKE2b-256 checksum
How to use checksums
3d1afe1c2770f389b426e49191db73ade31f1cdd447022c2a360b1f4809d9280
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

1.0.1 This release

11 release files

1.0.0

6 release files

0.1.0

6 release files

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