Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ concurrency:
env:
FORCE_COLOR: 3
PROJECT_NAME: "pted"
# Keep matplotlib off any GUI backend. The runners ship a tkinter that
# matplotlib will happily select and that then fails to initialise Tcl.
# tests/conftest.py sets this too; belt and braces, and it also covers any
# plotting reached outside pytest.
MPLBACKEND: Agg

jobs:
build:
runs-on: ${{matrix.os}}
strategy:
fail-fast: true
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
os: [ubuntu-latest, windows-latest, macOS-latest]
Expand Down Expand Up @@ -51,11 +56,6 @@ jobs:
python -m pip install --upgrade pip
pip install pytest pytest-cov wheel

- name: Install torch # no torch on 3.13 to test no-torch scenario
if: ${{ matrix.python-version != '3.13' }}
run: |
pip install torch

# We only want to install this on one run, because otherwise we'll have
# duplicate annotations.
- name: Install error reporter
Expand All @@ -68,6 +68,13 @@ jobs:
pip install -e .[dev]
pip show ${{ env.PROJECT_NAME }}

# The dev extra deliberately omits torch, so skipping this leaves 3.13
# genuinely torch-free and the no-torch code path gets exercised.
- name: Install torch # no torch on 3.13 to test no-torch scenario
if: ${{ matrix.python-version != '3.13' }}
run: |
pip install -e .[torch]

- name: Test with pytest
run: |
pytest -vvv --cov=${{ env.PROJECT_NAME }} --cov-report=xml --cov-report=term tests/
Expand Down
267 changes: 186 additions & 81 deletions README.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ Repository = "https://github.com/ConnorStoneAstro/pted"
Issues = "https://github.com/ConnorStoneAstro/pted/issues"

[project.optional-dependencies]
# Deliberately no torch: CI installs it per matrix entry via the `torch`
# extra below, leaving one entry without it so the no-torch code path is
# actually exercised. Pulling it in here would defeat that. For a local
# environment that runs the whole suite: pip install -e '.[dev,torch]'
dev = [
"pytest>=8.0,<9",
"pytest-cov>=4.1,<5",
"pytest-mock>=3.12,<4",
"torch>=2.0,<3",
"jax>=0.7,<1",
"matplotlib",
]
Expand Down
3 changes: 2 additions & 1 deletion src/pted/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .pted import pted, pted_coverage_test
from .pted import pted, pted_coverage_test, pted_containment_test
from .tests import test
from .utils import hdp_coverage_test
from ._version import version as __version__ # noqa
Expand All @@ -9,6 +9,7 @@
__all__ = [
"pted",
"pted_coverage_test",
"pted_containment_test",
"hdp_coverage_test",
"test",
"__version__",
Expand Down
383 changes: 293 additions & 90 deletions src/pted/pted.py

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions src/pted/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ def test():
np.random.seed(42)
# example 2 sample test
D = 300
for _ in range(20):
x = np.random.normal(size=(100, D))
y = np.random.normal(size=(100, D))
p = pted(x, y)
assert p > 1e-2 and p < 0.99, f"p-value {p} is not in the expected range (U(0,1))"
# Under the null these are U(0,1), so any single draw can land anywhere:
# check the batch, not each p-value. Asserting 0.01 < p < 0.99 on each of
# 20 uniform draws fails a third of the time on its own.
pvals = [
pted(np.random.normal(size=(100, D)), np.random.normal(size=(100, D))) for _ in range(20)
]
median = float(np.median(pvals))
assert 0.1 < median < 0.9, f"null p-values are not U(0,1): median {median}, {pvals}"

x = np.random.normal(size=(100, D))
y = np.random.uniform(size=(100, D))
Expand Down
Loading
Loading