Skip to content

Commit b2085cd

Browse files
committed
feat: added shortest_path()
1 parent 9a43090 commit b2085cd

File tree

10 files changed

+340
-227
lines changed

10 files changed

+340
-227
lines changed

src/codegen/internal_functions.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ from .conversion import * # noqa
66
from .enums import * # noqa
77
from .lib import * # noqa
88
from .types import (
9+
BoolArray,
910
EdgeLike,
1011
EdgeSelector,
12+
IntArray,
1113
MatrixLike,
1214
MatrixIntLike,
15+
RealArray,
1316
VertexLike,
1417
VertexPair,
1518
VertexSelector,

src/codegen/types.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CSTRING:
3737

3838
VECTOR:
3939
PY_TYPE: Iterable[float]
40-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_real_t]
40+
PY_RETURN_TYPE: RealArray
4141
INCONV:
4242
IN: "%C% = iterable_to_igraph_vector_t_view(%I%)"
4343
INOUT: "%C% = iterable_to_igraph_vector_t(%I%)"
@@ -46,7 +46,7 @@ VECTOR:
4646

4747
VECTOR_INT:
4848
PY_TYPE: Iterable[int]
49-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
49+
PY_RETURN_TYPE: IntArray
5050
INCONV:
5151
IN: "%C% = iterable_to_igraph_vector_int_t_view(%I%)"
5252
INOUT: "%C% = iterable_to_igraph_vector_int_t(%I%)"
@@ -57,7 +57,7 @@ VECTOR_BOOL:
5757
# we can convert anything into a bool, but we declare the type as
5858
# Iterable[bool] only to nudge the user towards using bools
5959
PY_TYPE: Iterable[bool]
60-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_bool_t]
60+
PY_RETURN_TYPE: BoolArray
6161
INCONV:
6262
IN: "%C% = iterable_to_igraph_vector_bool_t_view(%I%)"
6363
INOUT: "%C% = iterable_to_igraph_vector_bool_t(%I%)"
@@ -66,7 +66,7 @@ VECTOR_BOOL:
6666

6767
INDEX_VECTOR:
6868
PY_TYPE: Iterable[int]
69-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
69+
PY_RETURN_TYPE: IntArray
7070
INCONV:
7171
IN: "%C% = iterable_to_igraph_vector_int_t_view(%I%)"
7272
INOUT: "%C% = iterable_to_igraph_vector_int_t(%I%)"
@@ -75,7 +75,7 @@ INDEX_VECTOR:
7575

7676
MATRIX:
7777
PY_TYPE: MatrixLike
78-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_real_t]
78+
PY_RETURN_TYPE: RealArray
7979
INCONV:
8080
IN: "%C% = sequence_to_igraph_matrix_t_view(%I%)"
8181
INOUT: "%C% = sequence_to_igraph_matrix_t(%I%)"
@@ -84,7 +84,7 @@ MATRIX:
8484

8585
MATRIX_INT:
8686
PY_TYPE: MatrixIntLike
87-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
87+
PY_RETURN_TYPE: IntArray
8888
INCONV:
8989
IN: "%C% = sequence_to_igraph_matrix_int_t_view(%I%)"
9090
INOUT: "%C% = sequence_to_igraph_matrix_int_t(%I%)"
@@ -112,7 +112,7 @@ VERTEX:
112112

113113
VERTEX_COLORS:
114114
PY_TYPE: Iterable[int]
115-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
115+
PY_RETURN_TYPE: IntArray
116116
INCONV:
117117
IN: "%C% = vertex_colors_to_igraph_vector_int_t_view(%I%, %I1%)"
118118
INOUT: "%C% = vertex_colors_to_igraph_vector_int_t(%I%, %I1%)"
@@ -121,15 +121,15 @@ VERTEX_COLORS:
121121

122122
VERTEX_INDICES:
123123
PY_TYPE: Iterable[VertexLike]
124-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
124+
PY_RETURN_TYPE: IntArray
125125
INCONV:
126126
IN: "%C% = iterable_vertex_indices_to_igraph_vector_int_t(%I%)"
127127
OUT: "%C% = _VectorInt.create(0)"
128128
OUTCONV: "%I% = igraph_vector_int_t_to_numpy_array(%C%)"
129129

130130
VERTEX_INDICES_LIST:
131131
PY_TYPE: Iterable[Iterable[VertexLike]]
132-
PY_RETURN_TYPE: List[npt.NDArray[np_type_of_igraph_integer_t]]
132+
PY_RETURN_TYPE: List[IntArray]
133133
INCONV:
134134
IN: "%C% = iterable_of_vertex_index_iterable_to_igraph_vector_int_list_t(%I%)"
135135
OUT: "%C% = _VectorIntList.create(0)"
@@ -151,7 +151,7 @@ VERTEX_SELECTOR:
151151

152152
VERTEX_QTYS:
153153
PY_TYPE: Iterable[float]
154-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_real_t]
154+
PY_RETURN_TYPE: RealArray
155155
INCONV:
156156
IN: "%C% = vertex_qtys_to_igraph_vector_t_view(%I%, %I1%)"
157157
INOUT: "%C% = vertex_qtys_to_igraph_vector_t(%I%, %I1%)"
@@ -167,7 +167,7 @@ EDGE:
167167

168168
EDGE_COLORS:
169169
PY_TYPE: Iterable[int]
170-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
170+
PY_RETURN_TYPE: IntArray
171171
INCONV:
172172
IN: "%C% = edge_colors_to_igraph_vector_int_t_view(%I%, %I1%)"
173173
INOUT: "%C% = edge_colors_to_igraph_vector_int_t(%I%, %I1%)"
@@ -176,15 +176,15 @@ EDGE_COLORS:
176176

177177
EDGE_INDICES:
178178
PY_TYPE: Iterable[EdgeLike]
179-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_integer_t]
179+
PY_RETURN_TYPE: IntArray
180180
INCONV:
181181
IN: "%C% = iterable_edge_indices_to_igraph_vector_int_t(%I%)"
182182
OUT: "%C% = _VectorInt.create(0)"
183183
OUTCONV: "%I% = igraph_vector_int_t_to_numpy_array(%C%)"
184184

185185
EDGE_INDICES_LIST:
186186
PY_TYPE: Iterable[Iterable[EdgeLike]]
187-
PY_RETURN_TYPE: List[npt.NDArray[np_type_of_igraph_integer_t]]
187+
PY_RETURN_TYPE: List[IntArray]
188188
INCONV:
189189
IN: "%C% = iterable_of_edge_index_iterable_to_igraph_vector_int_list_t(%I%)"
190190
OUT: "%C% = _VectorIntList.create(0)"
@@ -200,7 +200,7 @@ EDGE_SELECTOR:
200200

201201
EDGE_WEIGHTS:
202202
PY_TYPE: Iterable[float]
203-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_real_t]
203+
PY_RETURN_TYPE: RealArray
204204
INCONV:
205205
IN: "%C% = edge_weights_to_igraph_vector_t_view(%I%, %I1%)"
206206
INOUT: "%C% = edge_weights_to_igraph_vector_t(%I%, %I1%)"
@@ -209,7 +209,7 @@ EDGE_WEIGHTS:
209209

210210
EDGE_CAPACITIES:
211211
PY_TYPE: Iterable[float]
212-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_real_t]
212+
PY_RETURN_TYPE: RealArray
213213
INCONV:
214214
IN: "%C% = edge_capacities_to_igraph_vector_t_view(%I%, %I1%)"
215215
INOUT: "%C% = edge_capacities_to_igraph_vector_t(%I%, %I1%)"
@@ -218,7 +218,7 @@ EDGE_CAPACITIES:
218218

219219
BIPARTITE_TYPES:
220220
PY_TYPE: Iterable[Any]
221-
PY_RETURN_TYPE: npt.NDArray[np_type_of_igraph_bool_t]
221+
PY_RETURN_TYPE: BoolArray
222222
INCONV:
223223
IN: "%C% = iterable_to_igraph_vector_bool_t_view(%I%) if %I% is not None else None"
224224
INOUT: "%C% = iterable_to_igraph_vector_bool_t(%I%) if %I% is not None else None"

src/igraph_ctypes/_internal/conversion.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@
5656
np_type_of_igraph_bool_t,
5757
np_type_of_igraph_integer_t,
5858
np_type_of_igraph_real_t,
59+
BoolArray,
5960
EdgeLike,
6061
EdgeSelector,
62+
IntArray,
6163
MatrixLike,
6264
MatrixIntLike,
65+
RealArray,
6366
VertexLike,
6467
VertexPair,
6568
VertexSelector,
@@ -661,19 +664,15 @@ def igraph_vector_int_t_to_list(vector: _VectorInt) -> List[int]:
661664
return [int(igraph_vector_int_e(vector, i)) for i in range(n)]
662665

663666

664-
def igraph_matrix_t_to_numpy_array(
665-
matrix: _Matrix,
666-
) -> npt.NDArray[np_type_of_igraph_real_t]:
667+
def igraph_matrix_t_to_numpy_array(matrix: _Matrix) -> RealArray:
667668
shape = igraph_matrix_nrow(matrix), igraph_matrix_ncol(matrix)
668669
result = np.zeros(shape, dtype=np_type_of_igraph_real_t)
669670
if result.size > 0:
670671
memmove(result.ctypes.data, igraph_matrix_e_ptr(matrix, 0, 0), result.nbytes)
671672
return result
672673

673674

674-
def igraph_matrix_int_t_to_numpy_array(
675-
matrix: _MatrixInt,
676-
) -> npt.NDArray[np_type_of_igraph_integer_t]:
675+
def igraph_matrix_int_t_to_numpy_array(matrix: _MatrixInt) -> IntArray:
677676
shape = igraph_matrix_int_nrow(matrix), igraph_matrix_int_ncol(matrix)
678677
result = np.zeros(shape, dtype=np_type_of_igraph_integer_t)
679678
if result.size > 0:
@@ -683,29 +682,23 @@ def igraph_matrix_int_t_to_numpy_array(
683682
return result
684683

685684

686-
def igraph_vector_t_to_numpy_array(
687-
vector: _Vector,
688-
) -> npt.NDArray[np_type_of_igraph_real_t]:
685+
def igraph_vector_t_to_numpy_array(vector: _Vector) -> RealArray:
689686
n = igraph_vector_size(vector)
690687
result = np.zeros(n, dtype=np_type_of_igraph_real_t)
691688
if n > 0:
692689
memmove(result.ctypes.data, igraph_vector_e_ptr(vector, 0), result.nbytes)
693690
return result
694691

695692

696-
def igraph_vector_bool_t_to_numpy_array(
697-
vector: _VectorBool,
698-
) -> npt.NDArray[np_type_of_igraph_bool_t]:
693+
def igraph_vector_bool_t_to_numpy_array(vector: _VectorBool) -> BoolArray:
699694
n = igraph_vector_bool_size(vector)
700695
result = np.zeros(n, dtype=np_type_of_igraph_bool_t)
701696
if n > 0:
702697
memmove(result.ctypes.data, igraph_vector_bool_e_ptr(vector, 0), result.nbytes)
703698
return result
704699

705700

706-
def igraph_vector_int_t_to_numpy_array(
707-
vector: _VectorInt,
708-
) -> npt.NDArray[np_type_of_igraph_integer_t]:
701+
def igraph_vector_int_t_to_numpy_array(vector: _VectorInt) -> IntArray:
709702
n = igraph_vector_int_size(vector)
710703
result = np.zeros(n, dtype=np_type_of_igraph_integer_t)
711704
if n > 0:
@@ -715,7 +708,7 @@ def igraph_vector_int_t_to_numpy_array(
715708

716709
def igraph_vector_list_t_to_list_of_numpy_array(
717710
vector_list: _VectorList,
718-
) -> List[npt.NDArray[np_type_of_igraph_real_t]]:
711+
) -> List[RealArray]:
719712
n = igraph_vector_list_size(vector_list)
720713
vec = _Vector()
721714
result = []
@@ -733,7 +726,7 @@ def igraph_vector_list_t_to_list_of_numpy_array(
733726

734727
def igraph_vector_int_list_t_to_list_of_numpy_array(
735728
vector_list: _VectorIntList,
736-
) -> List[npt.NDArray[np_type_of_igraph_integer_t]]:
729+
) -> List[IntArray]:
737730
n = igraph_vector_int_list_size(vector_list)
738731
vec = _VectorInt()
739732
result = []

0 commit comments

Comments
 (0)