Skip to content

Fix eigh UPLO and zero-size eigh/svd on the CPU#3834

Open
kapellirohith wants to merge 1 commit into
ml-explore:mainfrom
kapellirohith:linalg-cpu-fixes
Open

Fix eigh UPLO and zero-size eigh/svd on the CPU#3834
kapellirohith wants to merge 1 commit into
ml-explore:mainfrom
kapellirohith:linalg-cpu-fixes

Conversation

@kapellirohith

@kapellirohith kapellirohith commented Jul 11, 2026

Copy link
Copy Markdown

Proposed changes

eigh/eigvalsh read the opposite triangle from what UPLO asks for.
The row-major buffer is handed to LAPACK, which reads it as its transpose,
so UPLO="L" actually used the upper triangle. Only observable when the
two triangles differ:

>>> a = mx.array([[1.0, 999.0], [2.0, 3.0]])
>>> mx.linalg.eigvalsh(a, UPLO="L", stream=mx.cpu)
array([-997.001, 1001], dtype=float32)     # before (upper triangle)
array([-0.236068, 4.23607], dtype=float32) # after, matches numpy

Also fixes crashes for zero-size inputs to eigh and svd: LAPACK
rejects lda = 0 and the batch-count division was by zero.

No behavior change for inputs with consistent triangles (symmetric or
Hermitian), which is why the existing tests didn't catch it.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

eigh read the opposite triangle from what UPLO asked for: the row-major
buffer is handed to LAPACK, which reads it as its transpose, so
UPLO="L" used the upper triangle. Only observable when the two
triangles differ.

Also fix crashes for zero-size inputs to eigh and svd: LAPACK rejects
lda = 0 and the batch-count division was by zero.
@kapellirohith kapellirohith marked this pull request as draft July 11, 2026 12:19
@kapellirohith kapellirohith marked this pull request as ready for review July 11, 2026 21:03
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