Skip to content

np.linalg.eigvals() unexpected results on ARM CPUs #18422

@millettmb

Description

@millettmb

Reproducing code example:

  1. Procure 2x EC2 instances, ideally a t2.micro (x86) and t4g.micro (ARM) running Ubuntu 20.04 LTS (freetier)
  2. sudo apt update && sudo apt install python3-pip && pip3 install numpy to install requirements
  3. Open a python3 interactive shell to run the following code:
import numpy as np
values = [-20, 2, 3, 4, 5, 4, 3, 2]
values = values[int(non_zero[0]):int(np.non_zero[-1])+1]
_, e = np.frexp(values[::-1])
c = int(-0.5 * (np.max(e) + np.min(e)))
p = values[::-1]
p = np.ldexp(p, c)
A = np.diag(np.full(p.size - 2, p[0]), k=-1)
A[0,:] = -p[1:]
eigenvalues = np.linalg.eigvals(A)
print(eigenvalues)

(All values up until the eigvals function call are equal on both machines)

On the ARM based CPU, you will see the following output:
[-0.14294258 -0.05014252 -0.06678331 -0.06036967 0.01308302 -0.29849543 0.23065051]

On the x86 based CPU, you will see the following output:
[-0.35561591+0.14999412j -0.35561591-0.14999412j -0.10977392+0.35797579j -0.10977392-0.35797579j 0.15723786+0.31047243j 0.15723786-0.31047243j 0.24130395+0.j ]

There is no stack trace or error thrown.

Error:

I believe that the eigenvalues produced on the ARM CPU are incorrect, as they do not include complex conjugate pairs (with real number input). It's been a while since I've studied linear algebra, but I believe this to be the case.

I found this error originally due to an issue I encountered with the numpy_financial package, which calls the np.linalg.eigvals function from the irr function. More information on the issue over there: numpy/numpy-financial#37

NumPy/Python version information:

Both machines running Ubuntu 20.04 LTS, kernel 5.4.0-1047-aws. Python version 3.8.5. Numpy version 1.20.1.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions