From 78abe35c27861c96aab91f2bc1f291cac423aace Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 21 Nov 2019 17:00:05 -0600 Subject: [PATCH 1/3] PythonExpressionMapper: Remove the deprecated usage of constant_mapper --- dagrt/codegen/expressions.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dagrt/codegen/expressions.py b/dagrt/codegen/expressions.py index 6f530ad..bc0bd04 100644 --- a/dagrt/codegen/expressions.py +++ b/dagrt/codegen/expressions.py @@ -128,13 +128,6 @@ class FortranExpressionMapper(StringifyMapper): # {{{ python -def _map_python_constant(constant): - if isinstance(constant, (float, np.number)): - if np.isinf(constant) or np.isnan(constant): - return "float('" + repr(constant) + "')" - return repr(constant) - - class PythonExpressionMapper(StringifyMapper): """Converts expressions to Python code.""" @@ -145,11 +138,17 @@ class PythonExpressionMapper(StringifyMapper): numpy is the name of the numpy module. """ - super(PythonExpressionMapper, self).__init__(_map_python_constant) + super(PythonExpressionMapper, self).__init__() self._name_manager = name_manager self._function_registry = function_registry self._numpy = numpy + def map_constant(self, expr, *args): + if isinstance(constant, (float, np.number)): + if np.isinf(constant) or np.isnan(constant): + return "float('" + repr(constant) + "')" + return repr(constant) + def map_foreign(self, expr, *args): if expr is None: return "None" -- GitLab From 3c4dbb1c27b19b2d882bc5a9f5004bf015f182ad Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 21 Nov 2019 17:01:03 -0600 Subject: [PATCH 2/3] Rename variable --- dagrt/codegen/expressions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dagrt/codegen/expressions.py b/dagrt/codegen/expressions.py index bc0bd04..6ab97e3 100644 --- a/dagrt/codegen/expressions.py +++ b/dagrt/codegen/expressions.py @@ -144,10 +144,10 @@ class PythonExpressionMapper(StringifyMapper): self._numpy = numpy def map_constant(self, expr, *args): - if isinstance(constant, (float, np.number)): - if np.isinf(constant) or np.isnan(constant): - return "float('" + repr(constant) + "')" - return repr(constant) + if isinstance(expr, (float, np.number)): + if np.isinf(expr) or np.isnan(expr): + return "float('" + repr(expr) + "')" + return repr(expr) def map_foreign(self, expr, *args): if expr is None: -- GitLab From b2c5c14972b8b169c9231401c60e64d97fe73f2c Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 21 Nov 2019 17:03:33 -0600 Subject: [PATCH 3/3] Also fix FortranExpressionMapper --- dagrt/codegen/expressions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dagrt/codegen/expressions.py b/dagrt/codegen/expressions.py index 6ab97e3..249abbc 100644 --- a/dagrt/codegen/expressions.py +++ b/dagrt/codegen/expressions.py @@ -36,7 +36,7 @@ class FortranExpressionMapper(StringifyMapper): """name_manager is a map from a variable name (as a string) to its representation (as a string). """ - super(FortranExpressionMapper, self).__init__(repr) + super(FortranExpressionMapper, self).__init__() self._name_manager = name_manager def map_constant(self, expr, enclosing_prec): -- GitLab