From ae4bba35a553ea3a4486f280577f6380ff49979d Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Thu, 10 Jun 2021 11:06:22 -0500 Subject: [PATCH] Move actx.np.linalg.norm() implementation bits from pyopencl to generic --- arraycontext/fake_numpy.py | 20 ++++++++++++++++++++ arraycontext/impl/pyopencl.py | 23 +---------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/arraycontext/fake_numpy.py b/arraycontext/fake_numpy.py index 0657ecb..7e9b189 100644 --- a/arraycontext/fake_numpy.py +++ b/arraycontext/fake_numpy.py @@ -192,6 +192,26 @@ class BaseFakeNumpyLinalgNamespace: if ary.size == 0: return 0 + if ord is None: + ord = 2 + + from arraycontext.impl import _is_meshmode_dofarray + + if _is_meshmode_dofarray(ary): + from warnings import warn + warn("Taking an actx.np.linalg.norm of a DOFArray is deprecated. " + "(DOFArrays use 2D arrays internally, and " + "actx.np.linalg.norm should compute matrix norms of those.) " + "This will stop working in 2022. " + "Use meshmode.dof_array.flat_norm instead.", + DeprecationWarning, stacklevel=2) + + import numpy.linalg as la + return la.norm( + [self.norm(_flatten_array(subary), ord=ord) + for _, subary in serialize_container(ary)], + ord=ord) + if ord == np.inf: return self._array_context.np.max(abs(ary)) elif isinstance(ord, Number) and ord > 0: diff --git a/arraycontext/impl/pyopencl.py b/arraycontext/impl/pyopencl.py index ec75e0f..d0777a6 100644 --- a/arraycontext/impl/pyopencl.py +++ b/arraycontext/impl/pyopencl.py @@ -164,28 +164,7 @@ def _flatten_array(ary): class _PyOpenCLFakeNumpyLinalgNamespace(BaseFakeNumpyLinalgNamespace): - def norm(self, ary, ord=None): - if ord is None: - ord = 2 - - from arraycontext.impl import _is_meshmode_dofarray - - if _is_meshmode_dofarray(ary): - from warnings import warn - warn("Taking an actx.np.linalg.norm of a DOFArray is deprecated. " - "(DOFArrays use 2D arrays internally, and " - "actx.np.linalg.norm should compute matrix norms of those.) " - "This will stop working in 2022. " - "Use meshmode.dof_array.flat_norm instead.", - DeprecationWarning, stacklevel=2) - - import numpy.linalg as la - return la.norm( - [self.norm(_flatten_array(subary), ord=ord) - for _, subary in serialize_container(ary)], - ord=ord) - - return super().norm(ary, ord) + pass # }}} -- GitLab