From 2c7f9427a6a691a6a937271a155c2a67fa225707 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 25 Jun 2024 12:45:29 -0500 Subject: [PATCH] Fix code generation for numpy scalars in Python target --- loopy/target/python.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/loopy/target/python.py b/loopy/target/python.py index 1940dab16..5760b56d5 100644 --- a/loopy/target/python.py +++ b/loopy/target/python.py @@ -25,6 +25,8 @@ from typing import Optional, Sequence, Tuple +import numpy as np + from pymbolic.mapper import Mapper from pymbolic.mapper.stringifier import StringifyMapper from genpy import Generable, Suite, Collection @@ -58,7 +60,10 @@ def rec(self, expr, prec, type_context=None, needed_dtype=None): __call__ = rec def map_constant(self, expr, enclosing_prec): - return repr(expr) + if isinstance(expr, np.generic): + return repr(expr).replace("np.", "_lpy_np.") + else: + return repr(expr) def map_variable(self, expr, enclosing_prec): if expr.name in self.codegen_state.var_subst_map: