From 20978c76ac1a68c5a67f4b121a5bf9f1d13a5fe3 Mon Sep 17 00:00:00 2001 From: Pablo Brubeck Date: Tue, 21 Nov 2023 11:43:28 +0000 Subject: [PATCH 1/2] Simplify LagrangeLineExpansionSet symbolic derivative tabulation --- FIAT/barycentric_interpolation.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/FIAT/barycentric_interpolation.py b/FIAT/barycentric_interpolation.py index 17c90c426..fbc1316d0 100644 --- a/FIAT/barycentric_interpolation.py +++ b/FIAT/barycentric_interpolation.py @@ -58,9 +58,14 @@ def tabulate(self, n, pts): return results def _tabulate(self, n, pts, order=0): - results = [self.tabulate(n, pts)] + vals = self.tabulate(n, pts) + results = [vals] for r in range(order): - results.append(numpy.dot(self.dmat, results[-1])) + vals = numpy.dot(self.dmat, vals) + if vals.dtype == object: + from sympy import simplify + vals = numpy.array(list(map(simplify, vals))) + results.append(vals) for r in range(order+1): shape = results[r].shape shape = shape[:1] + (1,)*r + shape[1:] From 1b2c89cfc7d96aebd46fbefe45a86493abbf3e81 Mon Sep 17 00:00:00 2001 From: Pablo Brubeck Date: Tue, 21 Nov 2023 22:25:13 +0000 Subject: [PATCH 2/2] use numpy.vectorize --- FIAT/barycentric_interpolation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FIAT/barycentric_interpolation.py b/FIAT/barycentric_interpolation.py index fbc1316d0..5bb9e10b0 100644 --- a/FIAT/barycentric_interpolation.py +++ b/FIAT/barycentric_interpolation.py @@ -54,7 +54,7 @@ def tabulate(self, n, pts): results[results != results] = 1.0 if results.dtype == object: from sympy import simplify - results = numpy.array(list(map(simplify, results))) + results = numpy.vectorize(simplify)(results) return results def _tabulate(self, n, pts, order=0): @@ -64,7 +64,7 @@ def _tabulate(self, n, pts, order=0): vals = numpy.dot(self.dmat, vals) if vals.dtype == object: from sympy import simplify - vals = numpy.array(list(map(simplify, vals))) + vals = numpy.vectorize(simplify)(vals) results.append(vals) for r in range(order+1): shape = results[r].shape