From 30e55fd72c04717f929b352e4f9a43e107617903 Mon Sep 17 00:00:00 2001 From: yemeen Date: Wed, 11 Mar 2026 20:35:19 -0400 Subject: [PATCH 1/2] update unused imports and type annotation issues --- src/ect/directions.py | 22 ++++++++++++---------- src/ect/embed_complex.py | 5 ----- src/ect/sect.py | 2 +- src/ect/validation/base.py | 2 +- src/ect/validation/rules.py | 14 +++++++------- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/ect/directions.py b/src/ect/directions.py index e974304..853b390 100644 --- a/src/ect/directions.py +++ b/src/ect/directions.py @@ -64,8 +64,8 @@ def __init__( self.endpoint = endpoint self._rng = np.random.RandomState(seed) - self._thetas = None - self._vectors = None + self._thetas: Optional[np.ndarray] = None + self._vectors: Optional[np.ndarray] = None self._initialize_directions() def _initialize_directions(self): @@ -146,12 +146,12 @@ def from_angles(cls, angles: Sequence[float]) -> "Directions": return instance @classmethod - def from_vectors(cls, vectors: Sequence[tuple]) -> "Directions": + def from_vectors(cls, vectors: Sequence[Sequence[float]]) -> "Directions": """ Create a Directions instance from custom direction vectors in any dimension. Args: - vectors (Sequence[tuple]): List or array of direction vectors (each must be nonzero). + vectors (Sequence[Sequence[float]]): List or array of direction vectors (each must be nonzero). Returns: Directions: Instance with normalized direction vectors and associated angles (if 2D). @@ -163,12 +163,12 @@ def from_vectors(cls, vectors: Sequence[tuple]) -> "Directions": - Vectors are normalized to unit length. - For 2D, angles are computed from the vectors and available via :attr:`thetas`. """ - vectors = np.array(vectors, dtype=float) - norms = np.linalg.norm(vectors, axis=1, keepdims=True) + vectors_array = np.array(vectors, dtype=float) + norms = np.linalg.norm(vectors_array, axis=1, keepdims=True) if np.any(norms == 0): raise ValueError("Zero-magnitude vectors are not allowed") - normalized = vectors / norms - instance = cls(len(vectors), Sampling.CUSTOM, dim=vectors.shape[1]) + normalized = vectors_array / norms + instance = cls(len(vectors_array), Sampling.CUSTOM, dim=vectors_array.shape[1]) instance._vectors = normalized if instance.dim == 2: instance._thetas = np.arctan2(normalized[:, 1], normalized[:, 0]) @@ -194,8 +194,8 @@ def thetas(self) -> np.ndarray: "Angle representation is only available for 2D directions." ) if self._thetas is None: - # Compute the angles from the vectors. self._thetas = np.arctan2(self.vectors[:, 1], self.vectors[:, 0]) + assert self._thetas is not None return self._thetas @property @@ -215,13 +215,15 @@ def vectors(self) -> np.ndarray: """ if self._vectors is None: if self.dim == 2: + thetas = self.thetas self._vectors = np.column_stack( - (np.cos(self._thetas), np.sin(self._thetas)) + (np.cos(thetas), np.sin(thetas)) ) else: raise ValueError( "Direction vectors for dimensions >2 should be generated during initialization." ) + assert self._vectors is not None return self._vectors def __len__(self) -> int: diff --git a/src/ect/embed_complex.py b/src/ect/embed_complex.py index 1deddc2..d5ccf0e 100644 --- a/src/ect/embed_complex.py +++ b/src/ect/embed_complex.py @@ -9,11 +9,6 @@ from sklearn.decomposition import PCA from .utils.naming import next_vert_name -from .utils.face_check import ( - point_in_polygon, - validate_face_embedding, - validate_edge_embedding, -) from .validation import EmbeddingValidator, ValidationRule diff --git a/src/ect/sect.py b/src/ect/sect.py index 9b56c92..3fee899 100644 --- a/src/ect/sect.py +++ b/src/ect/sect.py @@ -2,7 +2,7 @@ from .embed_complex import EmbeddedComplex from .directions import Directions from .results import ECTResult -from typing import Optional, Union +from typing import Optional import numpy as np diff --git a/src/ect/validation/base.py b/src/ect/validation/base.py index 76f1a7a..0881b9f 100644 --- a/src/ect/validation/base.py +++ b/src/ect/validation/base.py @@ -81,7 +81,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """ Validate a cell against this rule. diff --git a/src/ect/validation/rules.py b/src/ect/validation/rules.py index 2bc802f..797dc13 100644 --- a/src/ect/validation/rules.py +++ b/src/ect/validation/rules.py @@ -40,7 +40,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate that dimension is non-negative.""" if dim is not None and dim < 0: @@ -68,7 +68,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate vertex count matches cell dimension requirements.""" if dim is None: @@ -114,7 +114,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate coordinate dimensions are consistent.""" if self.dimension_checker is None or cell_coords is None: @@ -156,7 +156,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate that no other vertices lie on this edge's interior.""" is_valid, error_msg = validate_edge_embedding( @@ -185,7 +185,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate that no other vertices lie inside this face.""" is_valid, error_msg = validate_face_embedding( @@ -214,7 +214,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate that face edges don't intersect each other""" @@ -275,7 +275,7 @@ def validate( all_coords: np.ndarray, cell_indices: List[int], all_indices: List[int], - dim: int = None, + dim: Optional[int] = None, ) -> ValidationResult: """Validate that all boundary edges exist for this face.""" if self.edge_checker is None: From 9fdf0af1fa73e1bc69f2eb8d2c20b15364d901f6 Mon Sep 17 00:00:00 2001 From: yemeen Date: Wed, 11 Mar 2026 20:39:15 -0400 Subject: [PATCH 2/2] fix error message --- src/ect/ect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ect/ect.py b/src/ect/ect.py index 2828f6a..0bf4e87 100644 --- a/src/ect/ect.py +++ b/src/ect/ect.py @@ -74,8 +74,8 @@ def _ensure_directions(self, graph_dim, theta=None): if theta is not None and graph_dim != 2: raise ValueError( - "Theta must be provided for 2D graphs. " - "Use 'directions' or 'num_dirs' to specify directions." + "theta is only supported for 2D graphs. " + "Use 'directions' or 'num_dirs' for higher dimensions." ) if self.directions.dim != graph_dim: