@@ -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 :
0 commit comments