pymc-devs / pymc-devs/pytensor
test_mlx_eigh compares eigenvector signs, which are arbitrary
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 644
- Forks
- 208
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 16
Description
Description
tests/link/mlx/linalg/test_decomposition.py::test_mlx_eigh fails on main for both lower=True and lower=False, but the backend is not wrong: it compares raw eigenvector arrays, and the sign of an eigenvector is arbitrary.
The eigenvalues agree, and both results satisfy A v = w v; the eigenvectors differ by a per-column sign:
eigenvalues match: True
np v[:,0]: [-0.94071188 -0.19066783 -0.28054756]
mlx v[:,0]: [ 0.9407117 0.19066775 0.28054756]
per-column sign ratio: [-1. 1. -1.]
residual |A v - w v|: mlx 3.8e-07 numpy 7.8e-16
Suggested fix: normalise the sign before comparing — e.g. fix the sign of the largest-magnitude entry of each column, or compare |v| — rather than asserting on the raw array. The same consideration applies to test_mlx_svd.
Secondary observation from the residuals above: MLX computed this in float32 even though the input was float64. MLX has no float64 support, so the .astype(dtype=...) calls throughout pytensor/link/mlx/dispatch/linalg/ silently downcast a float64 graph. That may deserve its own issue — an explicit error or a documented warning would be safer than a silent precision loss in a Cholesky or a log-determinant.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/link/mlx/linalg/test_decomposition.py::test_mlx_eigh and run the failing cases for both lower=True and lower=False. Update the eigenvector comparison so arbitrary per-column signs do not cause failure, then apply the same consideration to test_mlx_svd and run the relevant decomposition tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100