From 8e97e9ce8303877ed787704298d00feb0449a2db Mon Sep 17 00:00:00 2001
From: Andreas Kloeckner <inform@tiker.net>
Date: Wed, 10 Jun 2009 22:52:34 -0400
Subject: [PATCH] Work around numpy's locale-sensitive repr(). (numpy bug
 #1137)

---
 pymbolic/compiler.py | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/pymbolic/compiler.py b/pymbolic/compiler.py
index db5fec3..cec0d08 100644
--- a/pymbolic/compiler.py
+++ b/pymbolic/compiler.py
@@ -6,9 +6,26 @@ from pymbolic.mapper.stringifier import StringifyMapper, PREC_NONE, PREC_SUM, PR
 
 
 
+def _constant_mapper(c):
+    # work around numpy bug #1137 (locale-sensitive repr)
+    # http://projects.scipy.org/numpy/ticket/1137
+    try:
+        import numpy
+    except ImportError:
+        pass
+    else:
+        if isinstance(c, numpy.floating):
+            c = float(c)
+        elif isinstance(c, numpy.complexfloating):
+            c = complex(c)
+
+    return repr(c)
+
+
 class CompileMapper(StringifyMapper):
     def __init__(self):
-        StringifyMapper.__init__(self, constant_mapper=repr)
+        StringifyMapper.__init__(self, 
+                constant_mapper=_constant_mapper)
 
     def map_polynomial(self, expr, enclosing_prec):
         # Use Horner's scheme to evaluate the polynomial
-- 
GitLab