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.
Description
tests/link/mlx/linalg/test_decomposition.py::test_mlx_eighfails onmainfor bothlower=Trueandlower=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: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 totest_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 throughoutpytensor/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.