Skip to content

Commit 845264c

Browse files
committed
feat: add converters for most container types
1 parent c80c559 commit 845264c

11 files changed

Lines changed: 887 additions & 19 deletions

File tree

‎src/codegen/internal_functions.py.in‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@ from .types import (
1818
MatrixLike,
1919
MatrixIntLike,
2020
RealArray,
21+
SIRSimulation,
2122
VertexLike,
2223
VertexPair,
2324
VertexSelector,
2425
)
2526
from .wrappers import (
2627
_Graph,
28+
_GraphList,
2729
_Matrix,
2830
_MatrixInt,
31+
_MatrixList,
32+
_SIRList,
33+
_StrVector,
2934
_Vector,
3035
_VectorBool,
3136
_VectorInt,
3237
_VectorIntList,
38+
_VectorList, # noqa: F401 (used by outputs of type VECTOR_LIST)
3339
_create_graph_from_boxed,
3440
)
3541

‎src/codegen/internal_lib.py.in‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ from .types import (
4747
igraph_rewiring_stats_t,
4848
igraph_rng_t,
4949
igraph_rng_type_t,
50+
igraph_sir_t,
5051
igraph_warning_handler_t,
5152
)
5253

@@ -255,6 +256,10 @@ igraph_vector_ptr_destroy = _lib.igraph_vector_ptr_destroy
255256
igraph_vector_ptr_destroy.restype = None
256257
igraph_vector_ptr_destroy.argtypes = [c_void_p]
257258

259+
igraph_vector_ptr_destroy_all = _lib.igraph_vector_ptr_destroy_all
260+
igraph_vector_ptr_destroy_all.restype = None
261+
igraph_vector_ptr_destroy_all.argtypes = [c_void_p]
262+
258263
igraph_vector_ptr_clear = _lib.igraph_vector_ptr_clear
259264
igraph_vector_ptr_clear.restype = None
260265
igraph_vector_ptr_clear.argtypes = [POINTER(igraph_vector_ptr_t)]
@@ -263,16 +268,36 @@ igraph_vector_ptr_get = _lib.igraph_vector_ptr_get
263268
igraph_vector_ptr_get.restype = c_void_p
264269
igraph_vector_ptr_get.argtypes = [POINTER(igraph_vector_ptr_t), igraph_int_t]
265270

271+
igraph_vector_ptr_push_back = _lib.igraph_vector_ptr_push_back
272+
igraph_vector_ptr_push_back.restype = handle_igraph_error_t
273+
igraph_vector_ptr_push_back.argtypes = [POINTER(igraph_vector_ptr_t), c_void_p]
274+
266275
igraph_vector_ptr_resize = _lib.igraph_vector_ptr_resize
267276
igraph_vector_ptr_resize.restype = handle_igraph_error_t
268277
igraph_vector_ptr_resize.argtypes = [POINTER(igraph_vector_ptr_t), igraph_int_t]
269278

279+
igraph_vector_ptr_set_item_destructor = _lib.igraph_vector_ptr_set_item_destructor
280+
igraph_vector_ptr_set_item_destructor.restype = c_void_p
281+
igraph_vector_ptr_set_item_destructor.argtypes = [POINTER(igraph_vector_ptr_t), c_void_p]
282+
270283
igraph_vector_ptr_size = _lib.igraph_vector_ptr_size
271284
igraph_vector_ptr_size.restype = igraph_int_t
272285
igraph_vector_ptr_size.argtypes = [POINTER(igraph_vector_ptr_t)]
273286

274287
# String vector type
275288

289+
igraph_strvector_init = _lib.igraph_strvector_init
290+
igraph_strvector_init.restype = handle_igraph_error_t
291+
igraph_strvector_init.argtypes = [POINTER(igraph_strvector_t), igraph_int_t]
292+
293+
igraph_strvector_destroy = _lib.igraph_strvector_destroy
294+
igraph_strvector_destroy.restype = None
295+
igraph_strvector_destroy.argtypes = [c_void_p]
296+
297+
igraph_strvector_get = _lib.igraph_strvector_get
298+
igraph_strvector_get.restype = c_char_p
299+
igraph_strvector_get.argtypes = [POINTER(igraph_strvector_t), igraph_int_t]
300+
276301
igraph_strvector_clear = _lib.igraph_strvector_clear
277302
igraph_strvector_clear.restype = None
278303
igraph_strvector_clear.argtypes = [POINTER(igraph_strvector_t)]
@@ -377,6 +402,46 @@ igraph_matrix_int_nrow = _lib.igraph_matrix_int_nrow
377402
igraph_matrix_int_nrow.restype = igraph_int_t
378403
igraph_matrix_int_nrow.argtypes = [POINTER(igraph_matrix_int_t)]
379404

405+
# List of matrices type
406+
407+
igraph_matrix_list_init = _lib.igraph_matrix_list_init
408+
igraph_matrix_list_init.restype = handle_igraph_error_t
409+
igraph_matrix_list_init.argtypes = [POINTER(igraph_matrix_list_t), igraph_int_t]
410+
411+
igraph_matrix_list_destroy = _lib.igraph_matrix_list_destroy
412+
igraph_matrix_list_destroy.restype = None
413+
igraph_matrix_list_destroy.argtypes = [c_void_p]
414+
415+
igraph_matrix_list_get_ptr = _lib.igraph_matrix_list_get_ptr
416+
igraph_matrix_list_get_ptr.restype = POINTER(igraph_matrix_t)
417+
igraph_matrix_list_get_ptr.argtypes = [POINTER(igraph_matrix_list_t), igraph_int_t]
418+
419+
igraph_matrix_list_push_back = _lib.igraph_matrix_list_push_back
420+
igraph_matrix_list_push_back.restype = handle_igraph_error_t
421+
igraph_matrix_list_push_back.argtypes = [POINTER(igraph_matrix_list_t), POINTER(igraph_matrix_t)]
422+
423+
igraph_matrix_list_size = _lib.igraph_matrix_list_size
424+
igraph_matrix_list_size.restype = igraph_int_t
425+
igraph_matrix_list_size.argtypes = [POINTER(igraph_matrix_list_t)]
426+
427+
# List of graphs type
428+
429+
igraph_graph_list_init = _lib.igraph_graph_list_init
430+
igraph_graph_list_init.restype = handle_igraph_error_t
431+
igraph_graph_list_init.argtypes = [POINTER(igraph_graph_list_t), igraph_int_t]
432+
433+
igraph_graph_list_destroy = _lib.igraph_graph_list_destroy
434+
igraph_graph_list_destroy.restype = None
435+
igraph_graph_list_destroy.argtypes = [c_void_p]
436+
437+
igraph_graph_list_remove_fast = _lib.igraph_graph_list_remove_fast
438+
igraph_graph_list_remove_fast.restype = handle_igraph_error_t
439+
igraph_graph_list_remove_fast.argtypes = [POINTER(igraph_graph_list_t), igraph_int_t, POINTER(igraph_t)]
440+
441+
igraph_graph_list_size = _lib.igraph_graph_list_size
442+
igraph_graph_list_size.restype = igraph_int_t
443+
igraph_graph_list_size.argtypes = [POINTER(igraph_graph_list_t)]
444+
380445
# List of vectors type
381446

382447
igraph_vector_list_init = _lib.igraph_vector_list_init
@@ -506,6 +571,12 @@ igraph_rng_set_default = _lib.igraph_rng_set_default
506571
igraph_rng_set_default.restype = POINTER(igraph_rng_t)
507572
igraph_rng_set_default.argtypes = [POINTER(igraph_rng_t)]
508573

574+
# Results of SIR simulations
575+
576+
igraph_sir_destroy = _lib.igraph_sir_destroy
577+
igraph_sir_destroy.restype = None
578+
igraph_sir_destroy.argtypes = [POINTER(igraph_sir_t)]
579+
509580
# Graph type
510581

511582
igraph_destroy = _lib.igraph_destroy

‎src/codegen/run.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ def main():
564564
"FileLike",
565565
"IntArray",
566566
"RealArray",
567+
"SIRSimulation",
567568
"VertexLike",
568569
"VertexPair",
569570
"VertexSelector",

‎src/codegen/types.yaml‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,40 @@ MATRIX_INT:
9999
OUT: "%C% = _MatrixInt.create(0, 0)"
100100
OUTCONV: "%I% = igraph_matrix_int_t_to_numpy_array(%C%)"
101101

102+
# Lists of vectors, matrices and strings
103+
104+
VECTOR_LIST:
105+
PY_TYPE: Iterable[Iterable[float]]
106+
PY_RETURN_TYPE: list[RealArray]
107+
INCONV:
108+
IN: "%C% = iterable_of_iterable_to_igraph_vector_list_t(%I%)"
109+
OUT: "%C% = _VectorList.create(0)"
110+
OUTCONV: "%I% = igraph_vector_list_t_to_list_of_numpy_array(%C%)"
111+
112+
VECTOR_INT_LIST:
113+
PY_TYPE: Iterable[Iterable[int]]
114+
PY_RETURN_TYPE: list[IntArray]
115+
INCONV:
116+
IN: "%C% = iterable_of_iterable_to_igraph_vector_int_list_t(%I%)"
117+
OUT: "%C% = _VectorIntList.create(0)"
118+
OUTCONV: "%I% = igraph_vector_int_list_t_to_list_of_numpy_array(%C%)"
119+
120+
MATRIX_LIST:
121+
PY_TYPE: Iterable[MatrixLike]
122+
PY_RETURN_TYPE: list[RealArray]
123+
INCONV:
124+
IN: "%C% = iterable_of_matrices_to_igraph_matrix_list_t(%I%)"
125+
OUT: "%C% = _MatrixList.create(0)"
126+
OUTCONV: "%I% = igraph_matrix_list_t_to_list_of_numpy_array(%C%)"
127+
128+
VECTOR_STR:
129+
PY_TYPE: Iterable[str]
130+
PY_RETURN_TYPE: list[str]
131+
INCONV:
132+
IN: "%C% = iterable_of_strings_to_igraph_strvector_t(%I%)"
133+
OUT: "%C% = _StrVector.create(0)"
134+
OUTCONV: "%I% = igraph_strvector_t_to_list(%C%)"
135+
102136
# Graph, vertex and edge related classes
103137

104138
GRAPH:
@@ -134,6 +168,25 @@ VERTEX_INDICES:
134168
OUT: "%C% = _VectorInt.create(0)"
135169
OUTCONV: "%I% = igraph_vector_int_t_to_numpy_array(%C%)"
136170

171+
GRAPH_LIST:
172+
PY_TYPE: Iterable[Graph]
173+
PY_RETURN_TYPE: list[Graph]
174+
INCONV:
175+
OUT: "%C% = _GraphList.create(0)"
176+
OUTCONV: "%I% = igraph_graph_list_t_to_list_of_graphs(%C%)"
177+
178+
GRAPH_PTR_LIST:
179+
PY_TYPE: Iterable[Graph]
180+
INCONV:
181+
IN: "%C% = iterable_of_graphs_to_igraph_vector_ptr_t(%I%)"
182+
183+
ALL_VERTEX_QTY:
184+
PY_TYPE: Iterable[float]
185+
PY_RETURN_TYPE: RealArray
186+
INCONV:
187+
OUT: "%C% = _Vector.create(0)"
188+
OUTCONV: "%I% = igraph_vector_t_to_numpy_array(%C%)"
189+
137190
VERTEX_INDICES_LIST:
138191
PY_TYPE: Iterable[Iterable[VertexLike]]
139192
PY_RETURN_TYPE: list[IntArray]
@@ -268,6 +321,15 @@ VERTEX_ATTRIBUTE_COMBINATION:
268321
DEFAULT:
269322
Default: "None"
270323

324+
# Results of simulations
325+
326+
SIR_LIST:
327+
PY_TYPE: Iterable[SIRSimulation]
328+
PY_RETURN_TYPE: list[SIRSimulation]
329+
INCONV:
330+
OUT: "%C% = _SIRList.create(0)"
331+
OUTCONV: "%I% = igraph_sir_list_to_list_of_sir_simulations(%C%)"
332+
271333
# File I/O
272334

273335
INFILE:

0 commit comments

Comments
 (0)