From 346543ac55c2875513687a965944bff07f9a7f55 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 14 Jan 2021 09:22:37 -0600 Subject: [PATCH] Handle numbers in PyOpenCLArrayContext.np.la.norm --- meshmode/array_context.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meshmode/array_context.py b/meshmode/array_context.py index 6ed336e9b..1b7059541 100644 --- a/meshmode/array_context.py +++ b/meshmode/array_context.py @@ -373,6 +373,8 @@ def norm(self, array, ord=None): if ord is None: ord = 2 + from numbers import Number + # Handling DOFArrays here is not beautiful, but it sure does avoid # downstream headaches. from meshmode.dof_array import DOFArray @@ -381,11 +383,12 @@ def norm(self, array, ord=None): return la.norm(np.array([ self.norm(_flatten_grp_array(grp_ary), ord) for grp_ary in array]), ord) + elif isinstance(array, Number): + return abs(array) if array.size == 0: return 0 - from numbers import Number if ord == np.inf: return self._array_context.np.max(abs(array)) elif isinstance(ord, Number) and ord > 0: