Skip to content

Commit e6040c2

Browse files
authored
Merge pull request #98 from MunchLab/fix-static-analysis
update unused imports and type annotation issues
2 parents 5219ac3 + 9fdf0af commit e6040c2

6 files changed

Lines changed: 23 additions & 26 deletions

File tree

src/ect/directions.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def __init__(
6464
self.endpoint = endpoint
6565

6666
self._rng = np.random.RandomState(seed)
67-
self._thetas = None
68-
self._vectors = None
67+
self._thetas: Optional[np.ndarray] = None
68+
self._vectors: Optional[np.ndarray] = None
6969
self._initialize_directions()
7070

7171
def _initialize_directions(self):
@@ -146,12 +146,12 @@ def from_angles(cls, angles: Sequence[float]) -> "Directions":
146146
return instance
147147

148148
@classmethod
149-
def from_vectors(cls, vectors: Sequence[tuple]) -> "Directions":
149+
def from_vectors(cls, vectors: Sequence[Sequence[float]]) -> "Directions":
150150
"""
151151
Create a Directions instance from custom direction vectors in any dimension.
152152
153153
Args:
154-
vectors (Sequence[tuple]): List or array of direction vectors (each must be nonzero).
154+
vectors (Sequence[Sequence[float]]): List or array of direction vectors (each must be nonzero).
155155
156156
Returns:
157157
Directions: Instance with normalized direction vectors and associated angles (if 2D).
@@ -163,12 +163,12 @@ def from_vectors(cls, vectors: Sequence[tuple]) -> "Directions":
163163
- Vectors are normalized to unit length.
164164
- For 2D, angles are computed from the vectors and available via :attr:`thetas`.
165165
"""
166-
vectors = np.array(vectors, dtype=float)
167-
norms = np.linalg.norm(vectors, axis=1, keepdims=True)
166+
vectors_array = np.array(vectors, dtype=float)
167+
norms = np.linalg.norm(vectors_array, axis=1, keepdims=True)
168168
if np.any(norms == 0):
169169
raise ValueError("Zero-magnitude vectors are not allowed")
170-
normalized = vectors / norms
171-
instance = cls(len(vectors), Sampling.CUSTOM, dim=vectors.shape[1])
170+
normalized = vectors_array / norms
171+
instance = cls(len(vectors_array), Sampling.CUSTOM, dim=vectors_array.shape[1])
172172
instance._vectors = normalized
173173
if instance.dim == 2:
174174
instance._thetas = np.arctan2(normalized[:, 1], normalized[:, 0])
@@ -194,8 +194,8 @@ def thetas(self) -> np.ndarray:
194194
"Angle representation is only available for 2D directions."
195195
)
196196
if self._thetas is None:
197-
# Compute the angles from the vectors.
198197
self._thetas = np.arctan2(self.vectors[:, 1], self.vectors[:, 0])
198+
assert self._thetas is not None
199199
return self._thetas
200200

201201
@property
@@ -215,13 +215,15 @@ def vectors(self) -> np.ndarray:
215215
"""
216216
if self._vectors is None:
217217
if self.dim == 2:
218+
thetas = self.thetas
218219
self._vectors = np.column_stack(
219-
(np.cos(self._thetas), np.sin(self._thetas))
220+
(np.cos(thetas), np.sin(thetas))
220221
)
221222
else:
222223
raise ValueError(
223224
"Direction vectors for dimensions >2 should be generated during initialization."
224225
)
226+
assert self._vectors is not None
225227
return self._vectors
226228

227229
def __len__(self) -> int:

src/ect/ect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def _ensure_directions(self, graph_dim, theta=None):
7474

7575
if theta is not None and graph_dim != 2:
7676
raise ValueError(
77-
"Theta must be provided for 2D graphs. "
78-
"Use 'directions' or 'num_dirs' to specify directions."
77+
"theta is only supported for 2D graphs. "
78+
"Use 'directions' or 'num_dirs' for higher dimensions."
7979
)
8080

8181
if self.directions.dim != graph_dim:

src/ect/embed_complex.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
from sklearn.decomposition import PCA
1010

1111
from .utils.naming import next_vert_name
12-
from .utils.face_check import (
13-
point_in_polygon,
14-
validate_face_embedding,
15-
validate_edge_embedding,
16-
)
1712
from .validation import EmbeddingValidator, ValidationRule
1813

1914

src/ect/sect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .embed_complex import EmbeddedComplex
33
from .directions import Directions
44
from .results import ECTResult
5-
from typing import Optional, Union
5+
from typing import Optional
66
import numpy as np
77

88

src/ect/validation/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def validate(
8181
all_coords: np.ndarray,
8282
cell_indices: List[int],
8383
all_indices: List[int],
84-
dim: int = None,
84+
dim: Optional[int] = None,
8585
) -> ValidationResult:
8686
"""
8787
Validate a cell against this rule.

src/ect/validation/rules.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def validate(
4040
all_coords: np.ndarray,
4141
cell_indices: List[int],
4242
all_indices: List[int],
43-
dim: int = None,
43+
dim: Optional[int] = None,
4444
) -> ValidationResult:
4545
"""Validate that dimension is non-negative."""
4646
if dim is not None and dim < 0:
@@ -68,7 +68,7 @@ def validate(
6868
all_coords: np.ndarray,
6969
cell_indices: List[int],
7070
all_indices: List[int],
71-
dim: int = None,
71+
dim: Optional[int] = None,
7272
) -> ValidationResult:
7373
"""Validate vertex count matches cell dimension requirements."""
7474
if dim is None:
@@ -114,7 +114,7 @@ def validate(
114114
all_coords: np.ndarray,
115115
cell_indices: List[int],
116116
all_indices: List[int],
117-
dim: int = None,
117+
dim: Optional[int] = None,
118118
) -> ValidationResult:
119119
"""Validate coordinate dimensions are consistent."""
120120
if self.dimension_checker is None or cell_coords is None:
@@ -156,7 +156,7 @@ def validate(
156156
all_coords: np.ndarray,
157157
cell_indices: List[int],
158158
all_indices: List[int],
159-
dim: int = None,
159+
dim: Optional[int] = None,
160160
) -> ValidationResult:
161161
"""Validate that no other vertices lie on this edge's interior."""
162162
is_valid, error_msg = validate_edge_embedding(
@@ -185,7 +185,7 @@ def validate(
185185
all_coords: np.ndarray,
186186
cell_indices: List[int],
187187
all_indices: List[int],
188-
dim: int = None,
188+
dim: Optional[int] = None,
189189
) -> ValidationResult:
190190
"""Validate that no other vertices lie inside this face."""
191191
is_valid, error_msg = validate_face_embedding(
@@ -214,7 +214,7 @@ def validate(
214214
all_coords: np.ndarray,
215215
cell_indices: List[int],
216216
all_indices: List[int],
217-
dim: int = None,
217+
dim: Optional[int] = None,
218218
) -> ValidationResult:
219219
"""Validate that face edges don't intersect each other"""
220220

@@ -275,7 +275,7 @@ def validate(
275275
all_coords: np.ndarray,
276276
cell_indices: List[int],
277277
all_indices: List[int],
278-
dim: int = None,
278+
dim: Optional[int] = None,
279279
) -> ValidationResult:
280280
"""Validate that all boundary edges exist for this face."""
281281
if self.edge_checker is None:

0 commit comments

Comments
 (0)