From fcc6c6fd0f64d3939b25d908f3a9a92a22baac7a Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Sat, 2 May 2020 16:31:25 -0500 Subject: [PATCH 1/3] operators: only bind interp when necessary * skip when the dd_in == dd_out * skip for constants --- grudge/symbolic/operators.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/grudge/symbolic/operators.py b/grudge/symbolic/operators.py index c1360b16..cb88fa64 100644 --- a/grudge/symbolic/operators.py +++ b/grudge/symbolic/operators.py @@ -146,15 +146,21 @@ class ElementwiseLinearOperator(Operator): class InterpolationOperator(Operator): def __init__(self, dd_in, dd_out): - import grudge.symbolic.primitives as prim - official_dd_in = prim.as_dofdesc(dd_in) - official_dd_out = prim.as_dofdesc(dd_out) + super(InterpolationOperator, self).__init__(dd_in, dd_out) - if official_dd_in == official_dd_out: - raise ValueError("Interpolating from {} to {}" - " does not do anything.".format(official_dd_in, official_dd_out)) + def __call__(self, expr): + from pytools.obj_array import with_object_array_or_scalar - super(InterpolationOperator, self).__init__(dd_in, dd_out) + def interp_one(subexpr): + if self.dd_in == self.dd_out: + return subexpr + elif isinstance(subexpr, (int, float, complex, np.number)): + return subexpr + else: + from grudge.symbolic.primitives import OperatorBinding + return OperatorBinding(self, subexpr) + + return with_object_array_or_scalar(interp_one, expr) mapper_method = intern("map_interpolation") -- GitLab From 52fbf4edbfca9aef393c5551098a06ec84819bb2 Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Mon, 11 May 2020 15:52:13 -0500 Subject: [PATCH 2/3] operators: use pymbolic.is_constant --- grudge/function_registry.py | 1 + grudge/symbolic/operators.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/grudge/function_registry.py b/grudge/function_registry.py index 2f56eba4..4d521560 100644 --- a/grudge/function_registry.py +++ b/grudge/function_registry.py @@ -136,6 +136,7 @@ class CElementwiseBinaryFunction(Function): return func(arg0, arg1) from pymbolic.primitives import Variable + @memoize_in(self, "map_call_knl_%s" % func_name) def knl(): i = Variable("i") diff --git a/grudge/symbolic/operators.py b/grudge/symbolic/operators.py index cb88fa64..5f5cd5c9 100644 --- a/grudge/symbolic/operators.py +++ b/grudge/symbolic/operators.py @@ -152,9 +152,10 @@ class InterpolationOperator(Operator): from pytools.obj_array import with_object_array_or_scalar def interp_one(subexpr): + from pymbolic.primitives import is_constant if self.dd_in == self.dd_out: return subexpr - elif isinstance(subexpr, (int, float, complex, np.number)): + elif is_constant(subexpr): return subexpr else: from grudge.symbolic.primitives import OperatorBinding -- GitLab From 22dff13d55d2aedcd56f897d478b8a6bffb52266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Thu, 14 May 2020 17:23:39 +0200 Subject: [PATCH 3/3] Apply suggestion to grudge/symbolic/operators.py --- grudge/symbolic/operators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/grudge/symbolic/operators.py b/grudge/symbolic/operators.py index 5f5cd5c9..9b6fd758 100644 --- a/grudge/symbolic/operators.py +++ b/grudge/symbolic/operators.py @@ -154,6 +154,7 @@ class InterpolationOperator(Operator): def interp_one(subexpr): from pymbolic.primitives import is_constant if self.dd_in == self.dd_out: + # no-op interpolation, go away return subexpr elif is_constant(subexpr): return subexpr -- GitLab