New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using matplotlib Qt severely affect floating points operation in numba #1569
Comments
I just tried to install gcc 9.8.5 with conda and I still have the same problem. |
This seems to be a locale-related problem in LLVM. A small reproducer (without matplotlib) is:
|
I haven't found any way to reproduce in LLVM without invoking Numba's compile chain. |
I've determined this happens at Numba's NRT optimization step, where we print out and re-parse the LLVM module. At that point the float constants are expressed in exponent notation (e.g. "1.230000e+01"), which LLVM fails to parse again when the wrong locale is selected. (@sklam, that's an interesting side-effect) |
I filed a bug upstream: https://llvm.org/bugs/show_bug.cgi?id=25788 and a patch at http://reviews.llvm.org/D15375 |
Issue #1569: implement runtime check for the LLVM locale bug
We now have a runtime check to error out when LLVM has the wrong behaviour, and our LLVM builds also add a patch fixing the issue. Closing as fixed. |
when building matplotlib from source (qt 4.8.7 - pyside), one way to revert LC_NUMERIC to 'C' is to patch this way --- lib/matplotlib/backends/backend_qt4.py 2016-12-18 21:05:26.000000000 +0100
+++ lib/matplotlib/backends/backend_qt4.py 2017-01-11 23:44:42.161493028 +0100
@@ -6,6 +6,7 @@
import os
import re
import signal
+import locale
import sys
import matplotlib
@@ -61,6 +62,7 @@
if DEBUG:
print('FigureCanvasQt qt4: ', figure)
_create_qApp()
+ locale.setlocale(locale.LC_NUMERIC, 'C') # NOTE: must call setlocale after qApp = QtWidgets.QApplication, in _create_qApp
# Note different super-calling style to backend_qt5
QtWidgets.QWidget.__init__(self)
more information here (read the Locale Settings part) |
I matplotlib Qt is imported before compiling a numba function which takes a vector a numpy array as a parameter, basic floating operators do no longer works and float are automatically converted to integer.
Here is a minimum example of this bug:
On my machine this returns:
Test before importing matplotlib: works
Output with a vector as parameter: 1.100000
Output with a scalar as parameter: 1.100000
Import matplotlib witout QT
Test with function compiled before importing matplotlib: works
Output with a vector as parameter: 1.100000
Output with a scalar as parameter: 1.100000
Test after importing matplotlib: fails
Output with a vector as parameter: 1.000000
Output with a scalar as parameter: 1.100000
If instead of Qt4Agg I use Agg, the problem disappears.
The problem seems to be dependent on the configuration. Testing the code on 3 machines, the bug was present in 2 configurations.
I'm using Ubuntu 15.04 with gcc 4.9.2 . The conda packages I'm using are listed in the attached file.
Conda packages.txt
The text was updated successfully, but these errors were encountered: