diff --git a/pymbolic/compiler.py b/pymbolic/compiler.py index db5fec38884504455b5bd7731c325f265fc2bd83..cec0d08e879053442ac731431b7103a5727dea36 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 diff --git a/pymbolic/mapper/stringifier.py b/pymbolic/mapper/stringifier.py index 2b79ace0d89e850265afaa440c3309dfbc204c15..754e9665f54cfdcb733b81f6cb5b8a0fbeb116ff 100644 --- a/pymbolic/mapper/stringifier.py +++ b/pymbolic/mapper/stringifier.py @@ -116,7 +116,7 @@ class StringifyMapper(pymbolic.mapper.RecursiveMapper): def map_polynomial(self, expr, enclosing_prec): from pymbolic.primitives import flattened_sum return self.rec(flattened_sum( - [coeff*base**exp for exp, coeff in expr.data[::-1]]), + [coeff*expr.base**exp for exp, coeff in expr.data[::-1]]), enclosing_prec) def map_list(self, expr, enclosing_prec):