Skip to content
Snippets Groups Projects
Commit ae4bba35 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Move actx.np.linalg.norm() implementation bits from pyopencl to generic

parent ef9da97b
No related branches found
No related tags found
No related merge requests found
...@@ -192,6 +192,26 @@ class BaseFakeNumpyLinalgNamespace: ...@@ -192,6 +192,26 @@ class BaseFakeNumpyLinalgNamespace:
if ary.size == 0: if ary.size == 0:
return 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: if ord == np.inf:
return self._array_context.np.max(abs(ary)) return self._array_context.np.max(abs(ary))
elif isinstance(ord, Number) and ord > 0: elif isinstance(ord, Number) and ord > 0:
......
...@@ -164,28 +164,7 @@ def _flatten_array(ary): ...@@ -164,28 +164,7 @@ def _flatten_array(ary):
class _PyOpenCLFakeNumpyLinalgNamespace(BaseFakeNumpyLinalgNamespace): class _PyOpenCLFakeNumpyLinalgNamespace(BaseFakeNumpyLinalgNamespace):
def norm(self, ary, ord=None): pass
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)
# }}} # }}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment