Skip to content

Commit

Permalink
port to actx.np.zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Aug 6, 2024
1 parent ccd32b8 commit 42875af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
25 changes: 16 additions & 9 deletions meshmode/discretization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ class Discretization:
.. automethod:: __init__
.. automethod:: copy
.. automethod:: empty
.. automethod:: zeros
.. automethod:: empty_like
.. automethod:: zeros_like
.. automethod:: nodes
.. automethod:: num_reference_derivative
Expand Down Expand Up @@ -472,10 +470,14 @@ def empty(self, actx: ArrayContext,
*None* (the default), a real vector will be returned.
"""
if not isinstance(actx, ArrayContext):
raise TypeError("'actx' must be an ArrayContext, not '%s'"
% type(actx).__name__)
raise TypeError(
f"'actx' must be an ArrayContext, not '{type(actx).__name__}'")

return self._new_array(actx, actx.empty, dtype=dtype)
warn(f"'{type(self).__name__}.empty' is deprecated and will be removed "
f"in 2025. Use '{type(self).__name__}.zeros' instead.",
DeprecationWarning, stacklevel=2)

return self._new_array(actx, actx.np.zeros, dtype=dtype)

def zeros(self, actx: ArrayContext,
dtype: Optional[np.dtype] = None) -> _DOFArray:
Expand All @@ -486,13 +488,18 @@ def zeros(self, actx: ArrayContext,
*None* (the default), a real vector will be returned.
"""
if not isinstance(actx, ArrayContext):
raise TypeError("'actx' must be an ArrayContext, not '%s'"
% type(actx).__name__)
raise TypeError(
f"'actx' must be an ArrayContext, not '{type(actx).__name__}'")

return self._new_array(actx, actx.zeros, dtype=dtype)
return self._new_array(actx, actx.np.zeros, dtype=dtype)

def empty_like(self, array: _DOFArray) -> _DOFArray:
return self.empty(array.array_context, dtype=array.entry_dtype)
warn(f"'{type(self).__name__}.empty_like' is deprecated and will be removed "
f"in 2025. Use '{type(self).__name__}.zeros_like' instead.",
DeprecationWarning, stacklevel=2)

actx = array.array_context
return self._new_array(actx, actx.np.zeros, dtype=array.entry_dtype)

def zeros_like(self, array: _DOFArray) -> _DOFArray:
return self.zeros(array.array_context, dtype=array.entry_dtype)
Expand Down
2 changes: 1 addition & 1 deletion meshmode/discretization/connection/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def group_pick_knl(is_surjective: bool):
else:
# If no batched data at all, return zeros for this
# particular group array
group_array = actx.zeros(
group_array = actx.np.zeros(
shape=(self.to_discr.groups[i_tgrp].nelements,
self.to_discr.groups[i_tgrp].nunit_dofs),
dtype=ary.entry_dtype)
Expand Down
6 changes: 4 additions & 2 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ def test_dof_array_pickling_tags(actx_factory):

from pickle import dumps, loads

state = DOFArray(actx, (actx.zeros((10, 10), "float64"),
actx.zeros((10, 10), "float64"),))
state = DOFArray(actx, (
actx.np.zeros((10, 10), dtype=np.float64),
actx.np.zeros((10, 10), dtype=np.float64),
))

state = actx.thaw(actx.freeze(actx.tag(FooTag(), state)))
state = actx.thaw(actx.freeze(actx.tag_axis(0, FooAxisTag(), state)))
Expand Down

0 comments on commit 42875af

Please sign in to comment.