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

Port to actx.np.zeros #423

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
36 changes: 16 additions & 20 deletions meshmode/discretization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,9 @@ class Discretization:

.. automethod:: __init__
.. automethod:: copy
.. automethod:: empty
.. automethod:: zeros
.. automethod:: empty_like
.. automethod:: zeros_like
.. automethod:: nodes
.. automethod:: num_reference_derivative
.. automethod:: quad_weights
"""

Expand Down Expand Up @@ -472,10 +469,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)
Comment on lines +475 to +477
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also adds a warning that Discretization.empty is deprecated following arraycontext.


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

def zeros(self, actx: ArrayContext,
dtype: Optional[np.dtype] = None) -> _DOFArray:
Expand All @@ -486,27 +487,22 @@ 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)

def num_reference_derivative(self,
ref_axes: Iterable[int],
vec: _DOFArray) -> _DOFArray:
warn(
"This method is deprecated and will go away in 2022.x. "
"Use 'meshmode.discretization.num_reference_derivative' instead.",
DeprecationWarning, stacklevel=2)

return num_reference_derivative(self, ref_axes, vec)

@memoize_method
def quad_weights(self) -> _DOFArray:
"""
Expand Down
9 changes: 1 addition & 8 deletions meshmode/discretization/connection/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,6 @@ def is_permutation(self, tol_multiplier: Optional[float] = None) -> bool:
for i_tgrp, cgrp in enumerate(self.groups)
for i_batch in range(len(cgrp.batches)))

def full_resample_matrix(self, actx: ArrayContext):
from warnings import warn
warn("This method is deprecated. Use 'make_direct_full_resample_matrix' "
"instead.", DeprecationWarning, stacklevel=2)

return make_direct_full_resample_matrix(actx, self)

# {{{ _global_point_pick_info_cache

def _per_target_group_pick_info(
Expand Down Expand Up @@ -844,7 +837,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
11 changes: 5 additions & 6 deletions meshmode/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def vertex_unit_coordinates(self) -> np.ndarray:

@classmethod
@abstractmethod
def make_group(cls, **kwargs: Any) -> MeshElementGroup:
def make_group(cls, *args: Any, **kwargs: Any) -> MeshElementGroup:
"""Instantiate a new group of class *cls*.

Unlike the constructor, this factory function performs additional
Expand Down Expand Up @@ -361,13 +361,12 @@ def vertex_unit_coordinates(self) -> np.ndarray:
return mp.unit_vertices_for_shape(self._modepy_shape).T

@classmethod
# Type ignore because I do not know how to annotate this factory
# function usage. Possible reference:
# https://github.com/python/typing/discussions/1191#discussioncomment-2796173
def make_group(cls, order: int, # type: ignore[override]
def make_group(cls,
order: int,
inducer marked this conversation as resolved.
Show resolved Hide resolved
vertex_indices: np.ndarray | None,
nodes: np.ndarray,
*, unit_nodes: np.ndarray | None = None,
*,
unit_nodes: np.ndarray | None = None,
dim: int | None = None) -> _ModepyElementGroup:

if unit_nodes is None:
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
Loading