Skip to content

Commit 7c09830

Browse files
committed
TYP: improve type annotations of arrays to also express constraints on dimensionality
1 parent f3cc0a5 commit 7c09830

File tree

7 files changed

+166
-157
lines changed

7 files changed

+166
-157
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ convention = "numpy"
167167
[tool.ruff.lint.per-file-ignores]
168168
"tests/**" = ["D"]
169169

170+
[tool.ty.rules]
171+
unused-type-ignore-comment = "ignore"
172+
170173
[tool.mypy]
171174
python_version = "3.11"
172175
show_error_codes = true

src/gpgi/_boundaries.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
from numpy.typing import NDArray
66

7-
from gpgi._typing import FloatT
7+
from gpgi._typing import F
88

99
BoundaryRecipeT = Callable[
1010
[
11-
NDArray[FloatT],
12-
NDArray[FloatT],
13-
NDArray[FloatT],
14-
NDArray[FloatT],
15-
NDArray[FloatT],
16-
NDArray[FloatT],
17-
NDArray[FloatT],
18-
NDArray[FloatT],
11+
NDArray[F],
12+
NDArray[F],
13+
NDArray[F],
14+
NDArray[F],
15+
NDArray[F],
16+
NDArray[F],
17+
NDArray[F],
18+
NDArray[F],
1919
Literal["left", "right"],
2020
dict[str, Any],
2121
],
22-
NDArray[FloatT],
22+
NDArray[F],
2323
]
2424

2525

@@ -125,64 +125,64 @@ def __contains__(self, key: str) -> bool:
125125

126126
# basic recipes
127127
def open_boundary(
128-
same_side_active_layer: NDArray[FloatT],
129-
same_side_ghost_layer: NDArray[FloatT],
130-
opposite_side_active_layer: NDArray[FloatT],
131-
opposite_side_ghost_layer: NDArray[FloatT],
132-
weight_same_side_active_layer: NDArray[FloatT],
133-
weight_same_side_ghost_layer: NDArray[FloatT],
134-
weight_opposite_side_active_layer: NDArray[FloatT],
135-
weight_opposite_side_ghost_layer: NDArray[FloatT],
128+
same_side_active_layer: NDArray[F],
129+
same_side_ghost_layer: NDArray[F],
130+
opposite_side_active_layer: NDArray[F],
131+
opposite_side_ghost_layer: NDArray[F],
132+
weight_same_side_active_layer: NDArray[F],
133+
weight_same_side_ghost_layer: NDArray[F],
134+
weight_opposite_side_active_layer: NDArray[F],
135+
weight_opposite_side_ghost_layer: NDArray[F],
136136
side: Literal["left", "right"],
137137
metadata: dict[str, Any],
138-
) -> NDArray[FloatT]:
138+
) -> NDArray[F]:
139139
# return the active layer unchanged
140140
return same_side_active_layer
141141

142142

143143
def wall_boundary(
144-
same_side_active_layer: NDArray[FloatT],
145-
same_side_ghost_layer: NDArray[FloatT],
146-
opposite_side_active_layer: NDArray[FloatT],
147-
opposite_side_ghost_layer: NDArray[FloatT],
148-
weight_same_side_active_layer: NDArray[FloatT],
149-
weight_same_side_ghost_layer: NDArray[FloatT],
150-
weight_opposite_side_active_layer: NDArray[FloatT],
151-
weight_opposite_side_ghost_layer: NDArray[FloatT],
144+
same_side_active_layer: NDArray[F],
145+
same_side_ghost_layer: NDArray[F],
146+
opposite_side_active_layer: NDArray[F],
147+
opposite_side_ghost_layer: NDArray[F],
148+
weight_same_side_active_layer: NDArray[F],
149+
weight_same_side_ghost_layer: NDArray[F],
150+
weight_opposite_side_active_layer: NDArray[F],
151+
weight_opposite_side_ghost_layer: NDArray[F],
152152
side: Literal["left", "right"],
153153
metadata: dict[str, Any],
154-
) -> NDArray[FloatT]:
155-
return cast("NDArray[FloatT]", same_side_active_layer + same_side_ghost_layer)
154+
) -> NDArray[F]:
155+
return cast("NDArray[F]", same_side_active_layer + same_side_ghost_layer)
156156

157157

158158
def antisymmetric_boundary(
159-
same_side_active_layer: NDArray[FloatT],
160-
same_side_ghost_layer: NDArray[FloatT],
161-
opposite_side_active_layer: NDArray[FloatT],
162-
opposite_side_ghost_layer: NDArray[FloatT],
163-
weight_same_side_active_layer: NDArray[FloatT],
164-
weight_same_side_ghost_layer: NDArray[FloatT],
165-
weight_opposite_side_active_layer: NDArray[FloatT],
166-
weight_opposite_side_ghost_layer: NDArray[FloatT],
159+
same_side_active_layer: NDArray[F],
160+
same_side_ghost_layer: NDArray[F],
161+
opposite_side_active_layer: NDArray[F],
162+
opposite_side_ghost_layer: NDArray[F],
163+
weight_same_side_active_layer: NDArray[F],
164+
weight_same_side_ghost_layer: NDArray[F],
165+
weight_opposite_side_active_layer: NDArray[F],
166+
weight_opposite_side_ghost_layer: NDArray[F],
167167
side: Literal["left", "right"],
168168
metadata: dict[str, Any],
169-
) -> NDArray[FloatT]:
170-
return cast("NDArray[FloatT]", same_side_active_layer - same_side_ghost_layer)
169+
) -> NDArray[F]:
170+
return cast("NDArray[F]", same_side_active_layer - same_side_ghost_layer)
171171

172172

173173
def periodic_boundary(
174-
same_side_active_layer: NDArray[FloatT],
175-
same_side_ghost_layer: NDArray[FloatT],
176-
opposite_side_active_layer: NDArray[FloatT],
177-
opposite_side_ghost_layer: NDArray[FloatT],
178-
weight_same_side_active_layer: NDArray[FloatT],
179-
weight_same_side_ghost_layer: NDArray[FloatT],
180-
weight_opposite_side_active_layer: NDArray[FloatT],
181-
weight_opposite_side_ghost_layer: NDArray[FloatT],
174+
same_side_active_layer: NDArray[F],
175+
same_side_ghost_layer: NDArray[F],
176+
opposite_side_active_layer: NDArray[F],
177+
opposite_side_ghost_layer: NDArray[F],
178+
weight_same_side_active_layer: NDArray[F],
179+
weight_same_side_ghost_layer: NDArray[F],
180+
weight_opposite_side_active_layer: NDArray[F],
181+
weight_opposite_side_ghost_layer: NDArray[F],
182182
side: Literal["left", "right"],
183183
metadata: dict[str, Any],
184-
) -> NDArray[FloatT]:
185-
return cast("NDArray[FloatT]", same_side_active_layer + opposite_side_ghost_layer)
184+
) -> NDArray[F]:
185+
return cast("NDArray[F]", same_side_active_layer + opposite_side_ghost_layer)
186186

187187

188188
_base_registry: dict[str, BoundaryRecipeT] = {

0 commit comments

Comments
 (0)