Skip to content

Commit

Permalink
adds test_leaf_array_type_broadcasting
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushikcfd committed Jun 29, 2021
1 parent 4790d86 commit f0e0587
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,36 @@ def test_container_equality(actx_factory):
assert isinstance(bcast_dc_of_dofs == bcast_dc_of_dofs_2, MyContainerDOFBcast)


@with_container_arithmetic(
bcast_obj_array=True,
bcast_numpy_array=True,
rel_comparison=True,
_cls_has_array_context_attr=True)
@dataclass_array_container
@dataclass(frozen=True)
class Foo:
u: DOFArray

@property
def array_context(self):
return self.u.array_context


def test_leaf_array_type_broadcasting(actx_factory):
actx = actx_factory()

foo = Foo(DOFArray(actx, (actx.zeros(3, dtype=np.float64) + 41, )))
bar = foo + 4
baz = foo + actx.from_numpy(4*np.ones((3, )))
qux = actx.from_numpy(4*np.ones((3, ))) + foo

np.testing.assert_allclose(bar.u[0].get(),
baz.u[0].get())

np.testing.assert_allclose(bar.u[0].get(),
qux.u[0].get())


if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
Expand Down

0 comments on commit f0e0587

Please sign in to comment.