66from typing import Iterable , List
77
88import numpy as np
9+ import numpy .typing as npt
910
1011from .exceptions import GraphFormatError , InputError
1112from .graph import Edge , Float , Graph , Vertex
@@ -25,8 +26,9 @@ def __post_init__(self) -> None:
2526 """Validate initialization arguments and allocate adjacency storage."""
2627 if not isinstance (self .n , int ) or self .n <= 0 :
2728 raise InputError ("Graph.n must be a positive integer." )
28- self .adj : List [np .ndarray ] = [
29- np .zeros ((0 , 2 ), dtype = float ) for _ in range (self .n )
29+ # Use proper numpy typing
30+ self .adj : List [npt .NDArray [np .float64 ]] = [
31+ np .zeros ((0 , 2 ), dtype = np .float64 ) for _ in range (self .n )
3032 ]
3133
3234 def add_edge (self , u : Vertex , v : Vertex , w : Float ) -> None :
@@ -38,7 +40,7 @@ def add_edge(self, u: Vertex, v: Vertex, w: Float) -> None:
3840 if w < 0 :
3941 raise GraphFormatError (f"negative weight { w } on edge ({ u } , { v } )" )
4042 arr = self .adj [u ]
41- self .adj [u ] = np .vstack ([arr , np .array ([[v , float (w )]])])
43+ self .adj [u ] = np .vstack ([arr , np .array ([[v , float (w )]], dtype = np . float64 )])
4244
4345 @classmethod
4446 def from_edges (cls , n : int , edges : Iterable [Edge ]) -> "NumpyGraph" :
0 commit comments