Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle numbers in PyOpenCLArrayContext.np.la.norm #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion meshmode/array_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down