From 4a08cadaad9c82e656fc1e7bb37496f1ffaf5adb Mon Sep 17 00:00:00 2001 From: Matthias Diener <mdiener@illinois.edu> Date: Mon, 14 Jun 2021 11:23:24 -0500 Subject: [PATCH] fix norm() --- arraycontext/fake_numpy.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arraycontext/fake_numpy.py b/arraycontext/fake_numpy.py index e5c281c..97ee9ef 100644 --- a/arraycontext/fake_numpy.py +++ b/arraycontext/fake_numpy.py @@ -179,19 +179,6 @@ class BaseFakeNumpyLinalgNamespace: if isinstance(ary, Number): return abs(ary) - if is_array_container(ary): - import numpy.linalg as la - return la.norm( - [self.norm(subary, ord=ord) - for _, subary in serialize_container(ary)], - ord=ord) - - if len(ary.shape) != 1: - raise NotImplementedError("only vector norms are implemented") - - if ary.size == 0: - return 0 - if ord is None: ord = 2 @@ -213,6 +200,19 @@ class BaseFakeNumpyLinalgNamespace: for _, subary in serialize_container(ary)], ord=ord) + if is_array_container(ary): + import numpy.linalg as la + return la.norm( + [self.norm(subary, ord=ord) + for _, subary in serialize_container(ary)], + ord=ord) + + if len(ary.shape) != 1: + raise NotImplementedError("only vector norms are implemented") + + if ary.size == 0: + return 0 + if ord == np.inf: return self._array_context.np.max(abs(ary)) elif isinstance(ord, Number) and ord > 0: -- GitLab