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

Fix RUF052 and numpy 2.2 typecheck failures #446

Merged
merged 1 commit into from
Dec 16, 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
54 changes: 34 additions & 20 deletions meshmode/mesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,20 +1210,32 @@ def __init__(
if _nodal_adjacency is None:
if nodal_adjacency is not None:
warn("Passing 'nodal_adjacency' is deprecated and will be removed "
"in 2025. Use the underscore '_nodal_adjacency' instead to "
"in 2025. Use the underscored '_nodal_adjacency' instead to "
"match the dataclass field.",
DeprecationWarning, stacklevel=2)

_nodal_adjacency = nodal_adjacency
actual_nodal_adjacency = nodal_adjacency
else:
if nodal_adjacency is not None:
raise TypeError("passing both _nodal_adjacency and nodal adjacency "
"is not allowed")
else:
actual_nodal_adjacency = _nodal_adjacency

if _facial_adjacency_groups is None:
if facial_adjacency_groups is not None:
warn("Passing 'facial_adjacency_groups' is deprecated and will be "
"removed in 2025. Use the underscore '_facial_adjacency_groups'"
"removed in 2025. Use the underscored '_facial_adjacency_groups'"
" instead to match the dataclass field.",
DeprecationWarning, stacklevel=2)

_facial_adjacency_groups = facial_adjacency_groups
actual_facial_adjacency_groups = facial_adjacency_groups
else:
if facial_adjacency_groups is not None:
raise TypeError("passing both _facial_adjacency_groups "
"and facial adjacency_groups is not allowed")
else:
actual_facial_adjacency_groups = _facial_adjacency_groups

if not factory_constructed:
warn(f"Calling '{type(self).__name__}(...)' constructor is deprecated. "
Expand All @@ -1239,28 +1251,28 @@ def __init__(
is_conforming = None

if not is_conforming:
if _nodal_adjacency is None:
_nodal_adjacency = False
if _facial_adjacency_groups is None:
_facial_adjacency_groups = False
if actual_nodal_adjacency is None:
actual_nodal_adjacency = False
if actual_facial_adjacency_groups is None:
actual_facial_adjacency_groups = False

if (
_nodal_adjacency is not False
and _nodal_adjacency is not None):
if not isinstance(_nodal_adjacency, NodalAdjacency):
nb_starts, nbs = _nodal_adjacency
_nodal_adjacency = NodalAdjacency(
actual_nodal_adjacency is not False
and actual_nodal_adjacency is not None):
if not isinstance(actual_nodal_adjacency, NodalAdjacency):
nb_starts, nbs = actual_nodal_adjacency
actual_nodal_adjacency = NodalAdjacency(
neighbors_starts=nb_starts,
neighbors=nbs)

del nb_starts
del nbs

if (
_facial_adjacency_groups is not False
and _facial_adjacency_groups is not None):
_facial_adjacency_groups = _complete_facial_adjacency_groups(
_facial_adjacency_groups,
actual_facial_adjacency_groups is not False
and actual_facial_adjacency_groups is not None):
actual_facial_adjacency_groups = _complete_facial_adjacency_groups(
actual_facial_adjacency_groups,
element_id_dtype,
face_id_dtype)

Expand All @@ -1270,9 +1282,9 @@ def __init__(
object.__setattr__(self, "vertex_id_dtype", vertex_id_dtype)
object.__setattr__(self, "element_id_dtype", element_id_dtype)
object.__setattr__(self, "face_id_dtype", face_id_dtype)
object.__setattr__(self, "_nodal_adjacency", _nodal_adjacency)
object.__setattr__(self, "_nodal_adjacency", actual_nodal_adjacency)
object.__setattr__(self, "_facial_adjacency_groups",
_facial_adjacency_groups)
actual_facial_adjacency_groups)

if __debug__ and not factory_constructed and not skip_tests:
check_mesh_consistency(
Expand Down Expand Up @@ -1708,7 +1720,9 @@ def vertex_index_map_func(vertices: np.ndarray) -> np.ndarray:
# faces with the same vertices
order = np.lexsort(face_vertex_indices_increasing)
diffs = np.diff(face_vertex_indices_increasing[:, order], axis=1)
match_indices, = (~np.any(diffs, axis=0)).nonzero()
no_diff_flags = ~np.any(diffs, axis=0)
assert isinstance(no_diff_flags, np.ndarray)
match_indices, = no_diff_flags.nonzero()

return np.stack((order[match_indices], order[match_indices+1]))

Expand Down
5 changes: 3 additions & 2 deletions meshmode/mesh/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass, replace
from functools import reduce
from typing import Literal
from typing import Any, Literal

import numpy as np
import numpy.linalg as la
Expand Down Expand Up @@ -1059,7 +1059,8 @@ def _match_vertices(
for ivertex in range(len(tgt_vertex_indices)):
tree.insert(ivertex, tgt_vertex_bboxes[:, :, ivertex])

matched_tgt_vertices = np.full(len(src_vertex_indices), -1)
matched_tgt_vertices: np.ndarray[tuple[int, ...], np.dtype[Any]] \
= np.full(len(src_vertex_indices), -1)
for ivertex in range(len(src_vertex_indices)):
mapped_src_vertex = mapped_src_vertices[:, ivertex]
matches = np.array(list(tree.generate_matches(mapped_src_vertex)))
Expand Down
Loading