test_matrix fails on i386
olebole opened this issue · 4 comments
On i386, I get the following failure:
def test_matrix():
m = Minuit(lambda x, y: x**2 + (y / 2) ** 2 + 1, x=0, y=0)
m.errordef = 1
m.migrad()
> assert (
framed(tab.tabulate(*m.covariance.to_table()))
== """
x y
-- ------ ------
x 1 -0.643
y -0.643 4
"""
)
E AssertionError: assert '\n x ... 0 4\n' == '\n x... -0.643 4\n'
E
E - x y
E ? --- ---
E + x y
E - -- ------ ------
E + -- --- ---
E - x 1 -0.643
E ? --- ----
E + x 1 0
E ? +
E - y -0.643 4
E + y 0 4
tests/test_tabulate.py:33: AssertionError
I am unsure what the cause is; earlier compilations do not show this behavior. This appeards independent of whether the change taken from #776 (see #830) was applied or not.
Looking at the code, I am surprised why this test ever passed?! The answer you got is correct, the off-diagonal elements of the covariance matrix for this cost function should be zero, not -0.643. I will fix this.
🤦 That was an ugly bug in the formatting code which tries to produce a matrix that looks reasonable for humans instead of something like [[1, 1.23e-16], [1.23e-16, 4]]. The numerical result was actually correct.
Unfortunately, it still fails on i386 (2.21.3):
x y
-- --- ---
- x 1 -0
? ^
+ x 1 0
? ^
- y -0 4
? ^
+ y 0 4
? ^
I guess it's a precision problem on i386?
Due to differences in library implementations, it is possible that positive numbers near zero come out negative. I think this should be fixed in the pdf_format function, it should remove the minus sign if the number after rounding is zero.