Skip to content

Commit 6db3e75

Browse files
committed
type fixes
1 parent 4055f1a commit 6db3e75

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

adaptive/learner/learnerND.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def curvature_loss(simplex, values, value_scale, neighbors, neighbor_values):
201201

202202

203203
def choose_point_in_simplex(
204-
simplex: np.ndarray, transform: Optional[np.ndarray] = None
204+
simplex: Simplex, transform: Optional[np.ndarray] = None
205205
) -> np.ndarray:
206206
"""Choose a new point in inside a simplex.
207207

adaptive/learner/triangulation.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
from numpy.linalg import det as ndet
2727
from numpy.linalg import matrix_rank, norm, slogdet, solve
2828

29-
SimplexPoints = Union[List[Tuple[float, ...]], ndarray] # XXX: check if this is correct
30-
Simplex = Union[Tuple[numbers.Integral, ...], ndarray]
31-
Point = Union[Tuple[float, ...], ndarray] # XXX: check if this is correct
29+
SimplexPoints = Union[List[Tuple[float, ...]], ndarray]
30+
Simplex = Union[Iterable[numbers.Integral], ndarray]
31+
Point = Union[Tuple[float, ...], ndarray]
32+
Points = Union[Sequence[Point], ndarray]
3233

3334

3435
def fast_norm(v: Union[Tuple[float, ...], ndarray]) -> float:
@@ -78,7 +79,7 @@ def point_in_simplex(
7879
return all(alpha > -eps) and sum(alpha) < 1 + eps
7980

8081

81-
def fast_2d_circumcircle(points: Sequence[Point]) -> Tuple[Tuple[float, float], float]:
82+
def fast_2d_circumcircle(points: Points) -> Tuple[Tuple[float, float], float]:
8283
"""Compute the center and radius of the circumscribed circle of a triangle
8384
8485
Parameters
@@ -115,7 +116,7 @@ def fast_2d_circumcircle(points: Sequence[Point]) -> Tuple[Tuple[float, float],
115116

116117

117118
def fast_3d_circumcircle(
118-
points: Sequence[Point],
119+
points: Points,
119120
) -> Tuple[Tuple[float, float, float], float]:
120121
"""Compute the center and radius of the circumscribed sphere of a simplex.
121122
@@ -215,7 +216,7 @@ def circumsphere(pts: ndarray) -> Tuple[Tuple[float, ...], float]:
215216
return tuple(center), radius
216217

217218

218-
def orientation(face: ndarray, origin: ndarray) -> int:
219+
def orientation(face: Union[tuple, ndarray], origin: Union[tuple, ndarray]) -> int:
219220
"""Compute the orientation of the face with respect to a point, origin.
220221
221222
Parameters
@@ -238,7 +239,7 @@ def orientation(face: ndarray, origin: ndarray) -> int:
238239
sign, logdet = slogdet(vectors - origin)
239240
if logdet < -50: # assume it to be zero when it's close to zero
240241
return 0
241-
return sign
242+
return int(sign)
242243

243244

244245
def is_iterable_and_sized(obj: Any) -> bool:
@@ -326,7 +327,7 @@ class Triangulation:
326327
or more simplices in the
327328
"""
328329

329-
def __init__(self, coords: Union[Sequence[Point], ndarray]) -> None:
330+
def __init__(self, coords: Points) -> None:
330331
if not is_iterable_and_sized(coords):
331332
raise TypeError("Please provide a 2-dimensional list of points")
332333
coords = list(coords)
@@ -378,7 +379,7 @@ def add_simplex(self, simplex: Simplex) -> None:
378379
self.vertex_to_simplices[vertex].add(simplex)
379380

380381
def get_vertices(
381-
self, indices: Sequence[numbers.Integral]
382+
self, indices: Iterable[numbers.Integral]
382383
) -> List[Optional[Point]]:
383384
return [self.get_vertex(i) for i in indices]
384385

@@ -389,7 +390,7 @@ def get_vertex(self, index: Optional[numbers.Integral]) -> Optional[Point]:
389390

390391
def get_reduced_simplex(
391392
self, point: Point, simplex: Simplex, eps: float = 1e-8
392-
) -> list:
393+
) -> List[numbers.Integral]:
393394
"""Check whether vertex lies within a simplex.
394395
395396
Returns
@@ -440,7 +441,7 @@ def faces(
440441
dim: Optional[int] = None,
441442
simplices: Optional[Iterable[Simplex]] = None,
442443
vertices: Optional[Iterable[int]] = None,
443-
) -> Iterator[Tuple[int, ...]]:
444+
) -> Iterator[Tuple[numbers.Integral, ...]]:
444445
"""Iterator over faces of a simplex or vertex sequence."""
445446
if dim is None:
446447
dim = self.dim
@@ -525,7 +526,7 @@ def circumscribed_circle(
525526

526527
def point_in_cicumcircle(
527528
self, pt_index: int, simplex: Simplex, transform: ndarray
528-
) -> bool:
529+
) -> Union[bool, np.bool_]:
529530
# return self.fast_point_in_circumcircle(pt_index, simplex, transform)
530531
eps = 1e-8
531532

@@ -603,7 +604,7 @@ def bowyer_watson(
603604
new_triangles = self.vertex_to_simplices[pt_index]
604605
return bad_triangles - new_triangles, new_triangles - bad_triangles
605606

606-
def _simplex_is_almost_flat(self, simplex: Simplex) -> bool:
607+
def _simplex_is_almost_flat(self, simplex: Simplex) -> Union[bool, np.bool_]:
607608
return self._relative_volume(simplex) < 1e-8
608609

609610
def _relative_volume(self, simplex: Simplex) -> float:
@@ -728,7 +729,7 @@ def find_opposing_vertex(vertex: int):
728729
return result
729730

730731
@property
731-
def hull(self) -> Set[int]:
732+
def hull(self) -> Set[numbers.Integral]:
732733
"""Compute hull from triangulation.
733734
734735
Parameters

0 commit comments

Comments
 (0)