Skip to content

Fix Pfaffian backward for numerically singular inputs#15

Merged
JeremieGince merged 1 commit into
devfrom
fix/singular-pfaffian-backward
Jul 2, 2026
Merged

Fix Pfaffian backward for numerically singular inputs#15
JeremieGince merged 1 commit into
devfrom
fix/singular-pfaffian-backward

Conversation

@JeremieGince

@JeremieGince JeremieGince commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace the exact pf == 0 singularity check in PfaffianStrategy's backward pass with two dtype-adaptive criteria: a relative-magnitude test on the Pfaffian and a residual check on the LU inverse, so numerically (not just exactly) singular or ill-conditioned matrices are routed to the exact minor-based adjugate instead of producing garbage or NaNs from the LU inverse.
  • Add SINGULARITY_RTOL_EXPONENT and INVERSE_RESIDUAL_RTOL_EXPONENT class constants that scale with torch.finfo(dtype).eps, keeping the thresholds correct across float32/float64.
  • Add test coverage for moderate ill-conditioning, ties between the two criteria, mixed-batch routing, and dtype adaptivity.

Test plan

  • pytest tests/test_strategies/test_strategy.py — 14 passed, 100% coverage on strategy.py
  • Full suite: pytest — 495 passed, 100% coverage

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
280 280 100% 98% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/torch_pfaffian/strategies/strategy.py 100% 🟢
TOTAL 100% 🟢

updated for commit: ae1af29 by action🐍

@JeremieGince JeremieGince merged commit a7e844c into dev Jul 2, 2026
11 checks passed
@JeremieGince JeremieGince deleted the fix/singular-pfaffian-backward branch July 2, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant