Description:
It seems like in the EllipseModel.fit function np.linalg.eig is called which returns either a complex matrix or casts to a real matrix if the matrix has no complex component. See here
The relevant code is found here:
|
eig_vals, eig_vecs = np.linalg.eig(M) |
|
|
We have been running into a problem where occasionally the np.linalg.eig() function will return a very small complex component some times. Most likely this is a result of some very small floating point error, maybe from the casting to 32 bit floats?
The code fails when it tries to find the remainder of a complex and float dtype:
If you want to see the failing CI check here
The solution here is to change it to
eig_vals, eig_vecs = np.linalg.eig(M).real
Way to reproduce:
It seems to fail about every 6-7 times if you want to test it.
import numpy as np
from skimage.measure.fit import EllipseModel
e = EllipseModel()
for i in range(100):
rand = np.random.rand(4,2)
print(rand)
e.estimate(rand)
This rarely would come up except if you are using something like np.random as most people don't have floats that extend to the full bit depth.
Version information:
3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0]
Linux-5.15.0-73-generic-x86_64-with-glibc2.29
scikit-image version: 0.21.0
numpy version: 1.21.6
Description:
It seems like in the
EllipseModel.fitfunction np.linalg.eig is called which returns either a complex matrix or casts to a real matrix if the matrix has no complex component. See hereThe relevant code is found here:
scikit-image/skimage/measure/fit.py
Lines 490 to 491 in 359d4e3
We have been running into a problem where occasionally the
np.linalg.eig()function will return a very small complex component some times. Most likely this is a result of some very small floating point error, maybe from the casting to 32 bit floats?The code fails when it tries to find the remainder of a complex and float dtype:
scikit-image/skimage/measure/fit.py
Line 538 in 359d4e3
If you want to see the failing CI check here
The solution here is to change it to
Way to reproduce:
It seems to fail about every 6-7 times if you want to test it.
This rarely would come up except if you are using something like np.random as most people don't have floats that extend to the full bit depth.
Version information: