numpy / numpy/numpy

BUG: `np.linalg.eigh(complex)` give wrong eigenvectors with accelerate and netlib blas

Open
#24,640 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug component: numpy.linalg
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

Describe the issue:

macos-arm (apple silicon M2) only, not reproducible on ubuntu-22.04,AMD-R7

call np.linalg.eigh on a hermitian complex matrix, the eigenvectors are wrong with accelerate and netlib blas, but correct with openblas.

env blas eigh
env00 accelerate wrong
env01 netlib wrong
env02 openblas correct
conda create -y -n env00 -c conda-forge "libblas=*=*accelerate" numpy

conda create -y -n env01 -c conda-forge "libblas=*=*netlib" numpy

# default if no blas specified
conda create -y -n env02 -c conda-forge "libblas=*=*openblas" numpy

seems related issue: numpy/numpy#21950

Reproduce the code example:
import numpy as np
np0 = np.array([[0,1j],[-1j,0]])
EVL,EVC = np.linalg.eigh(np0)
print(EVC)
print(EVC.T.conj() @ EVC)
Error message:
# wrong (accelerate,netlib), the first EVC is correct but not normalized, the second EVC is wrong in direction
# [[-0.70710678-0.70710678j  0.70710678+1.20710678j]
#  [ 0.70710678-0.70710678j  0.5       -0.70710678j]]
# [[ 2.        +0.j  -0.5       -0.5j]
#  [-0.5       +0.5j  2.70710678+0.j ]]

# correct (openblas)
# [[-0.70710678+0.j          0.70710678+0.j        ]
#  [ 0.        -0.70710678j  0.        -0.70710678j]]
# [[1.00000000e+00+0.j 2.23711432e-17+0.j]
#  [2.23711432e-17+0.j 1.00000000e+00+0.j]]
Runtime information:
import sys, numpy
print(numpy.__version__); print(sys.version)
## same for all: env00 env01 env02
# 1.25.2
# 3.11.5 | packaged by conda-forge | (main, Aug 27 2023, 03:33:12) [Clang 15.0.7 ]
Context for the issue:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied np.linalg.eigh example on macOS ARM with the accelerate, netlib, and openblas environments. Use the np.linalg.eigh entry point to compare the returned eigenvectors with the reported normalized, orthogonal result. Done means the affected BLAS configurations return correct eigenvectors for this reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.