Skip to content

Support type-2 and type-3 generalized Hermitian eigenproblems - #41197

Merged
copybara-service[bot] merged 1 commit into
jax-ml:mainfrom
jabrailkhalil:feat/scipy-eigh-problem-types
Oct 2, 2026
Merged

copybara-service[bot] merged 1 commit into
jax-ml:mainfrom
jabrailkhalil:feat/scipy-eigh-problem-types

Conversation

@jabrailkhalil

@jabrailkhalil jabrailkhalil commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

jax.scipy.linalg.eigh(a, b) currently rejects type=2 and type=3. This follows up on #41162 by supporting A B v = w v and B A v = w v using the existing Cholesky reduction and Hermitian eigensolver.

For both new problem types, the reduced matrix is Lᴴ A L, where B = L Lᴴ. Eigenvectors are transformed back with L⁻ᴴ for type 2 and L for type 3, preserving the corresponding B or B⁻¹ normalization. This uses the standard LAPACK reduction; type 1 retains its existing implementation. The docstring describes all three problem types, and invalid type values raise ValueError.

Tests cover SciPy agreement, defining equations, eigenvector normalization, real and complex inputs, broadcasting, JIT, vmap, input symmetrization, invalid arguments, and non-positive-definite B. Gradient coverage uses the existing forward/reverse finite-difference checks for all three problem types.

Related to #5461.

Current validation after the review-requested cleanup and CI-directed test adjustments (CPU, Python 3.12.14, jaxlib 0.11.2, SciPy 1.18.1):

  • Remaining generalized-eigh tests with JAX_ENABLE_X64=false and JAX_NUM_GENERATED_CASES=100: 111 passed, 0 skipped.
  • The same focused tests with JAX_ENABLE_X64=true and JAX_NUM_GENERATED_CASES=100: 163 passed, 0 skipped.
  • Changed-file pre-commit checks: passed, including Ruff and Pyrefly.

Earlier full-module and minimum-SciPy validation before the test-only cleanup (production implementation is unchanged):

  • JAX_ENABLE_X64=false python -m pytest -n 2 tests/linalg_test.py: 981 passed, 23 skipped.
  • JAX_ENABLE_X64=true python -m pytest -n 2 tests/linalg_test.py: 1074 passed, 26 skipped.
  • Focused tests (-k "GeneralizedEigh or EighType") with SciPy 1.15.0 / NumPy 2.2.6 and JAX_ENABLE_X64=false: 54 passed, 0 skipped.
  • pre-commit run --files jax/_src/scipy/linalg.py tests/linalg_test.py: passed, including Ruff and Pyrefly.

The all-files pre-commit run passes every hook except Jupytext, which reports an existing mismatch in the unchanged docs/autodidax2_part1.py / .md pair. I reproduced that failure on those files separately and verified that both match the base commit. GPU and TPU tests were not run.

CI follow-up: the float32/complex64 finite-difference step is now 1/128, with gradient tolerances unchanged. The defining-equation residual tolerance is 2e-5 on TPU, following an observed 1.4e-5 residual in the type-1 broadcast case; other backends retain 1e-5. Accelerator CI still needs to validate these test-only adjustments. The production implementation is unchanged.

@jakevdp jakevdp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good, thanks! I think the math is solid – just a couple testing changes.

Comment thread tests/linalg_test.py Resolved
Comment thread tests/linalg_test.py Resolved
@jakevdp jakevdp self-assigned this Oct 1, 2026

@jakevdp jakevdp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! Could you please squash the changes into a single commit?

@jabrailkhalil

jabrailkhalil commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

I squashed the changes into a single commit, as requested. I also addressed the numerical test failures reported by CI: the float32/complex64 finite-difference step is now 1/128 without relaxing the gradient tolerances, and the TPU defining-equation residual allows 2e-5 instead of 1e-5 (the reported error was about 1.4e-5). The production implementation is unchanged.

With 100 generated cases, the focused CPU tests pass with x64 off (111 passed) and on (163 passed); changed-file pre-commit checks pass. I have not rerun accelerator tests locally, so I am waiting for GPU/TPU CI to validate these adjustments. The earlier oneAPI build failure is in unchanged Triton/LLVM TableGen code, which appears separate from these Python changes.

The workflows on the latest head are currently held for maintainer approval (action_required), so the accelerator validation has not run yet. Please approve those runs when reviewing this revision.

@jabrailkhalil
jabrailkhalil force-pushed the feat/scipy-eigh-problem-types branch from 211ce8e to 7ae1ce0 Compare October 2, 2026 10:16
@jabrailkhalil
jabrailkhalil force-pushed the feat/scipy-eigh-problem-types branch from 7ae1ce0 to c22ca60 Compare October 2, 2026 10:35

@jakevdp jakevdp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@google-ml-butler google-ml-butler Bot added the pull ready Ready for copybara import and testing label Oct 2, 2026
@jabrailkhalil

Copy link
Copy Markdown
Contributor Author

CI update at the same single-commit head c22ca60f: the squash check passes, and the full CUDA 13 / Python 3.14 and TPU v6e / Python 3.14t jobs pass. Their logs explicitly report //tests:linalg_test_gpu and //tests:linalg_test_tpu as passed. Thank you for approving the runs.

Two checks remain red:

  • CPU Python 3.15: the sole failed target is lax_autodiff_test_cpu, in the complex64 second-order cosh case. The test, lax implementation, and shared test utilities are byte-identical to the PR base; this PR changes only the SciPy linalg implementation and its tests.
  • CUDA 12 / Python 3.12: the log reaches 152/153 completed targets, then remains on svd_test_gpu shard 9 until the 60-minute test step stops with a custom-container error. It does not report an eigh assertion failure; the unfinished job also failed to upload XML artifacts.

These look separate from this change based on the failing paths and logs; I have not run a base/head reproduction of those two failures. Could the failed checks be rerun when convenient? I am keeping the numerical implementation and tolerances unchanged while the remaining checks are assessed.

@copybara-service
copybara-service Bot merged commit e0af9e1 into jax-ml:main Oct 2, 2026
57 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pull ready Ready for copybara import and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants