Skip to content

Commit

Permalink
Switch to __array_ufunc__ as a way to avoid numpy broadcasting
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Aug 5, 2024
1 parent 03229d3 commit f278400
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def __init__(self, actx, data):
self.array_context = actx
self.data = data

__array_priority__ = 10
# prevent numpy broadcasting
__array_ufunc__ = None

def __bool__(self):
if len(self) == 1 and self.data[0].size == 1:
Expand Down Expand Up @@ -222,6 +223,8 @@ class MyContainer:
momentum: np.ndarray
enthalpy: Union[DOFArray, np.ndarray]

__array_ufunc__ = None

@property
def array_context(self):
if isinstance(self.mass, np.ndarray):
Expand Down Expand Up @@ -1367,7 +1370,8 @@ def test_container_equality(actx_factory):
class Foo:
u: DOFArray

__array_priority__ = 1 # disallow numpy arithmetic to take precedence
# prevent numpy arithmetic from taking precedence
__array_ufunc__ = None

@property
def array_context(self):
Expand Down

0 comments on commit f278400

Please sign in to comment.