From a4bebe88d42b16b30e79daeca5af412c3ff24036 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 2 Dec 2018 18:46:00 -0600 Subject: [PATCH 1/4] Help CSE in l2p --- sumpy/expansion/local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sumpy/expansion/local.py b/sumpy/expansion/local.py index 483bc0eb..88433257 100644 --- a/sumpy/expansion/local.py +++ b/sumpy/expansion/local.py @@ -130,7 +130,7 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): evaluated_coeffs = ( self.derivative_wrangler.get_full_kernel_derivatives_from_stored( coeffs, rscale)) - bvec = bvec * rscale**-1 + bvec = [sym.UnevaluatedExpr(b * rscale**-1) for b in bvec] result = sum( coeff * mi_power(bvec, mi) -- GitLab From ff02ff1228fbebab251691b825d73929ac13275b Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 2 Dec 2018 21:57:14 -0600 Subject: [PATCH 2/4] Use unevaluated pow instead of UnevaluatedExpr --- sumpy/expansion/local.py | 4 ++-- sumpy/symbolic.py | 7 +++++++ sumpy/tools.py | 7 +++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sumpy/expansion/local.py b/sumpy/expansion/local.py index 88433257..80912077 100644 --- a/sumpy/expansion/local.py +++ b/sumpy/expansion/local.py @@ -130,10 +130,10 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): evaluated_coeffs = ( self.derivative_wrangler.get_full_kernel_derivatives_from_stored( coeffs, rscale)) - bvec = [sym.UnevaluatedExpr(b * rscale**-1) for b in bvec] + bvec = bvec * rscale**-1 result = sum( coeff - * mi_power(bvec, mi) + * mi_power(bvec, mi, evaluate=False) / mi_factorial(mi) for coeff, mi in zip( evaluated_coeffs, self.get_full_coefficient_identifiers())) diff --git a/sumpy/symbolic.py b/sumpy/symbolic.py index c7ed61e6..1ddfb876 100644 --- a/sumpy/symbolic.py +++ b/sumpy/symbolic.py @@ -111,6 +111,13 @@ if not have_unevaluated_expr: return x +if USE_SYMENGINE: + def UnevaluatedPow(a, b): + return Pow(a, b) +else: + def UnevaluatedPow(a, b): + return Pow(a, b, evaluate=False) + # {{{ debugging of sympy CSE via Maxima class _DerivativeKiller(IdentityMapperBase): diff --git a/sumpy/tools.py b/sumpy/tools.py index 469cb5e1..4e71c43c 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -55,10 +55,13 @@ def mi_factorial(mi): return result -def mi_power(vector, mi): +def mi_power(vector, mi, evaluate=True): result = 1 for mi_i, vec_i in zip(mi, vector): - result *= vec_i**mi_i + if evaluate: + result *= vec_i**mi_i + else + result *= sym.UnevaluatedPow(vec_i, mi_i) return result -- GitLab From 79ae6104b7588b6c25a2a837b79ff3f96ed06f95 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 2 Dec 2018 22:06:09 -0600 Subject: [PATCH 3/4] Fix syntaxerror and lint errors --- sumpy/symbolic.py | 9 +++++---- sumpy/tools.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sumpy/symbolic.py b/sumpy/symbolic.py index 1ddfb876..7a86958a 100644 --- a/sumpy/symbolic.py +++ b/sumpy/symbolic.py @@ -112,11 +112,12 @@ if not have_unevaluated_expr: if USE_SYMENGINE: - def UnevaluatedPow(a, b): - return Pow(a, b) + def unevaluated_pow(a, b): + return sym.Pow(a, b) else: - def UnevaluatedPow(a, b): - return Pow(a, b, evaluate=False) + def unevaluated_pow(a, b): + return sym.Pow(a, b, evaluate=False) + # {{{ debugging of sympy CSE via Maxima diff --git a/sumpy/tools.py b/sumpy/tools.py index 4e71c43c..3b95349e 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -60,8 +60,8 @@ def mi_power(vector, mi, evaluate=True): for mi_i, vec_i in zip(mi, vector): if evaluate: result *= vec_i**mi_i - else - result *= sym.UnevaluatedPow(vec_i, mi_i) + else: + result *= sym.unevaluated_pow(vec_i, mi_i) return result -- GitLab From 72cf4849922625081a5a8775e2e13a0826e2dcd3 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 2 Dec 2018 22:20:53 -0600 Subject: [PATCH 4/4] Don't use unevaluate for 1 --- sumpy/tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sumpy/tools.py b/sumpy/tools.py index 3b95349e..c826ef2f 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -58,7 +58,9 @@ def mi_factorial(mi): def mi_power(vector, mi, evaluate=True): result = 1 for mi_i, vec_i in zip(mi, vector): - if evaluate: + if mi_i == 1: + result *= vec_i + elif evaluate: result *= vec_i**mi_i else: result *= sym.unevaluated_pow(vec_i, mi_i) -- GitLab