Skip to content

Commit 4aa92b9

Browse files
committed
refactor: regenerated code, migrated from igraph_integer_t to igraph_int_t
1 parent a3c2efb commit 4aa92b9

File tree

10 files changed

+1452
-1070
lines changed

10 files changed

+1452
-1070
lines changed

src/codegen/internal_lib.py.in

Lines changed: 65 additions & 65 deletions
Large diffs are not rendered by default.

src/codegen/types.yaml

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ BOOLEAN:
1313
INTEGER:
1414
PY_TYPE: int
1515
INCONV:
16-
OUT: "%C% = igraph_integer_t()"
16+
OUT: "%C% = igraph_int_t()"
17+
DEFAULT:
18+
UNLIMITED: "-1" # value of IGRAPH_UNLIMITED
1719

1820
REAL:
1921
PY_TYPE: float
2022
INCONV:
2123
OUT: "%C% = igraph_real_t()"
24+
DEFAULT:
25+
UNLIMITED: "-1" # value of IGRAPH_UNLIMITED
2226

2327
INT:
2428
PY_TYPE: int
@@ -110,8 +114,8 @@ VERTEX:
110114
PY_TYPE: VertexLike
111115
PY_RETURN_TYPE: int
112116
INCONV:
113-
IN: "%C% = vertexlike_to_igraph_integer_t(%I%)"
114-
OUT: "%C% = igraph_integer_t(0)"
117+
IN: "%C% = vertexlike_to_igraph_int_t(%I%)"
118+
OUT: "%C% = igraph_int_t(0)"
115119

116120
VERTEX_COLORS:
117121
PY_TYPE: Iterable[int]
@@ -152,12 +156,12 @@ VERTEX_SELECTOR:
152156
ALL: '"all"'
153157
CALL: "%C%.unwrap()"
154158

155-
VERTEX_QTYS:
159+
VERTEX_QTY:
156160
PY_TYPE: Iterable[float]
157161
PY_RETURN_TYPE: RealArray
158162
INCONV:
159-
IN: "%C% = vertex_qtys_to_igraph_vector_t_view(%I%, %I1%)"
160-
INOUT: "%C% = vertex_qtys_to_igraph_vector_t(%I%, %I1%)"
163+
IN: "%C% = vertex_qty_to_igraph_vector_t_view(%I%, %I1%)"
164+
INOUT: "%C% = vertex_qty_to_igraph_vector_t(%I%, %I1%)"
161165
OUT: "%C% = _Vector.create(0)"
162166
OUTCONV: "%I% = igraph_vector_t_to_numpy_array(%C%)"
163167

@@ -174,8 +178,8 @@ EDGE:
174178
PY_TYPE: EdgeLike
175179
PY_RETURN_TYPE: int
176180
INCONV:
177-
IN: "%C% = edgelike_to_igraph_integer_t(%I%)"
178-
OUT: "%C% = igraph_integer_t(0)"
181+
IN: "%C% = edgelike_to_igraph_int_t(%I%)"
182+
OUT: "%C% = igraph_int_t(0)"
179183

180184
EDGE_COLORS:
181185
PY_TYPE: Iterable[int]
@@ -312,11 +316,6 @@ EIGENALGO:
312316
INCONV:
313317
IN: "%C% = c_int(%I%)"
314318

315-
ERDOS_RENYI_TYPE:
316-
PY_TYPE: ErdosRenyiType
317-
INCONV:
318-
IN: "%C% = c_int(%I%)"
319-
320319
FAS_ALGORITHM:
321320
PY_TYPE: FeedbackArcSetAlgorithm
322321
INCONV:
@@ -332,11 +331,6 @@ GREEDY_COLORING_HEURISTIC:
332331
INCONV:
333332
IN: "%C% = c_int(%I%)"
334333

335-
IMITATE_ALGORITHM:
336-
PY_TYPE: ImitateAlgorithm
337-
INCONV:
338-
IN: "%C% = c_int(%I%)"
339-
340334
LAYOUT_GRID:
341335
PY_TYPE: LayoutGrid
342336
INCONV:
@@ -352,11 +346,6 @@ NEIMODE:
352346
INCONV:
353347
IN: "%C% = c_int(%I%)"
354348

355-
OPTIMALITY:
356-
PY_TYPE: Optimality
357-
INCONV:
358-
IN: "%C% = c_int(%I%)"
359-
360349
PAGERANKALGO:
361350
PY_TYPE: PagerankAlgorithm
362351
INCONV:
@@ -372,10 +361,8 @@ RECIP:
372361
INCONV:
373362
IN: "%C% = c_int(%I%)"
374363

375-
REWIRING_MODE:
376-
PY_TYPE: Rewiring
377-
INCONV:
378-
IN: "%C% = c_int(%I%)"
364+
REWIRING_STATS:
365+
PY_TYPE: ~
379366

380367
ROOTCHOICE:
381368
PY_TYPE: RootChoice

src/igraph_ctypes/_internal/conversion.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
)
6767
from .types import (
6868
igraph_bool_t,
69-
igraph_integer_t,
69+
igraph_int_t,
7070
igraph_real_t,
7171
np_type_of_igraph_bool_t,
72-
np_type_of_igraph_integer_t,
72+
np_type_of_igraph_int_t,
7373
np_type_of_igraph_real_t,
7474
AttributeCombinationSpecification,
7575
AttributeCombinationSpecificationEntry,
@@ -107,7 +107,7 @@
107107
"any_to_file_ptr",
108108
"any_to_igraph_bool_t",
109109
"bytes_to_str",
110-
"edgelike_to_igraph_integer_t",
110+
"edgelike_to_igraph_int_t",
111111
"edge_capacities_to_igraph_vector_t",
112112
"edge_capacities_to_igraph_vector_t_view",
113113
"edge_colors_to_igraph_vector_t",
@@ -148,13 +148,13 @@
148148
"sequence_to_igraph_matrix_int_t_view",
149149
"sequence_to_igraph_matrix_t",
150150
"sequence_to_igraph_matrix_t_view",
151-
"vertexlike_to_igraph_integer_t",
151+
"vertexlike_to_igraph_int_t",
152152
"vertex_pairs_to_igraph_vector_int_t",
153153
"vertex_selector_to_igraph_vs_t",
154154
"vertex_colors_to_igraph_vector_int_t",
155155
"vertex_colors_to_igraph_vector_int_t_view",
156-
"vertex_qtys_to_igraph_vector_t",
157-
"vertex_qtys_to_igraph_vector_t_view",
156+
"vertex_qty_to_igraph_vector_t",
157+
"vertex_qty_to_igraph_vector_t_view",
158158
"vertex_weights_to_igraph_vector_t",
159159
"vertex_weights_to_igraph_vector_t_view",
160160
)
@@ -228,10 +228,10 @@ def any_to_igraph_bool_t(obj: Any) -> igraph_bool_t:
228228
return igraph_bool_t(bool(obj))
229229

230230

231-
def edgelike_to_igraph_integer_t(edge: EdgeLike) -> igraph_integer_t:
231+
def edgelike_to_igraph_int_t(edge: EdgeLike) -> igraph_int_t:
232232
"""Converts an edge-like object to an igraph integer."""
233233
if isinstance(edge, int) and edge >= 0:
234-
return igraph_integer_t(edge)
234+
return igraph_int_t(edge)
235235
else:
236236
raise ValueError(f"{edge!r} cannot be converted to an igraph edge index")
237237

@@ -251,7 +251,7 @@ def edge_selector_to_igraph_es_t(selector: EdgeSelector, graph: Graph) -> _EdgeS
251251
indices = iterable_edge_indices_to_igraph_vector_int_t(selector) # type: ignore
252252
return _EdgeSelector.create_with(igraph_es_vector_copy, indices)
253253
else:
254-
index = edgelike_to_igraph_integer_t(selector) # type: ignore
254+
index = edgelike_to_igraph_int_t(selector) # type: ignore
255255
return _EdgeSelector.create_with(igraph_es_1, index)
256256

257257

@@ -312,7 +312,7 @@ def iterable_edge_indices_to_igraph_vector_int_t(
312312

313313
result = _VectorInt.create(0)
314314
for index in indices:
315-
igraph_vector_int_push_back(result, edgelike_to_igraph_integer_t(index))
315+
igraph_vector_int_push_back(result, edgelike_to_igraph_int_t(index))
316316
return result
317317

318318

@@ -399,7 +399,7 @@ def iterable_vertex_indices_to_igraph_vector_int_t(
399399

400400
result: _VectorInt = _VectorInt.create(0)
401401
for index in indices:
402-
igraph_vector_int_push_back(result, vertexlike_to_igraph_integer_t(index))
402+
igraph_vector_int_push_back(result, vertexlike_to_igraph_int_t(index))
403403
return result
404404

405405

@@ -502,7 +502,7 @@ def sequence_to_igraph_matrix_int_t(items: MatrixIntLike) -> _MatrixInt:
502502
else:
503503
_ensure_matrix(items)
504504
return numpy_array_to_igraph_matrix_int_t(
505-
np.array(items, dtype=np_type_of_igraph_integer_t)
505+
np.array(items, dtype=np_type_of_igraph_int_t)
506506
)
507507

508508

@@ -589,10 +589,10 @@ def numpy_array_to_igraph_matrix_t(arr: np.ndarray) -> _Matrix:
589589

590590
def numpy_array_to_igraph_matrix_int_t(arr: np.ndarray) -> _MatrixInt:
591591
"""Converts a two-dimensional NumPy array to an igraph matrix of integers."""
592-
arr = _force_into_2d_numpy_array(arr, np_type_of_igraph_integer_t)
592+
arr = _force_into_2d_numpy_array(arr, np_type_of_igraph_int_t)
593593
return _MatrixInt.create_with(
594594
igraph_matrix_int_init_array,
595-
arr.ctypes.data_as(POINTER(igraph_integer_t)),
595+
arr.ctypes.data_as(POINTER(igraph_int_t)),
596596
arr.shape[0],
597597
arr.shape[1],
598598
MatrixStorage.COLUMN_MAJOR,
@@ -637,10 +637,10 @@ def numpy_array_to_igraph_vector_int_t(
637637
arr: np.ndarray, flatten: bool = False
638638
) -> _VectorInt:
639639
"""Converts a one-dimensional NumPy array to an igraph vector of integers."""
640-
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_integer_t, flatten=flatten)
640+
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_int_t, flatten=flatten)
641641
return _VectorInt.create_with(
642642
igraph_vector_int_init_array,
643-
arr.ctypes.data_as(POINTER(igraph_integer_t)),
643+
arr.ctypes.data_as(POINTER(igraph_int_t)),
644644
arr.shape[0],
645645
)
646646

@@ -654,11 +654,11 @@ def numpy_array_to_igraph_vector_int_t_view(
654654
into the appropriate layout and data type first and then a view will be
655655
provided into the copy.
656656
"""
657-
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_integer_t, flatten=flatten)
657+
arr = _force_into_1d_numpy_array(arr, np_type_of_igraph_int_t, flatten=flatten)
658658

659659
result = _VectorInt()
660660
igraph_vector_int_view(
661-
result, arr.ctypes.data_as(POINTER(igraph_integer_t)), arr.shape[0]
661+
result, arr.ctypes.data_as(POINTER(igraph_int_t)), arr.shape[0]
662662
)
663663

664664
# Destructor must not be called so we never mark result as initialized;
@@ -697,10 +697,10 @@ def numpy_array_to_igraph_vector_t_view(
697697
return result
698698

699699

700-
def vertexlike_to_igraph_integer_t(vertex: VertexLike) -> igraph_integer_t:
700+
def vertexlike_to_igraph_int_t(vertex: VertexLike) -> igraph_int_t:
701701
"""Converts a vertex-like object to an igraph integer."""
702702
if isinstance(vertex, int) and vertex >= 0:
703-
return igraph_integer_t(vertex)
703+
return igraph_int_t(vertex)
704704
else:
705705
raise ValueError(f"{vertex!r} cannot be converted to an igraph vertex index")
706706

@@ -714,8 +714,8 @@ def vertex_pairs_to_igraph_vector_int_t(pairs: Iterable[VertexPair]) -> _VectorI
714714

715715
result: _VectorInt = _VectorInt.create(0)
716716
for u, v in pairs:
717-
igraph_vector_int_push_back(result, vertexlike_to_igraph_integer_t(u))
718-
igraph_vector_int_push_back(result, vertexlike_to_igraph_integer_t(v))
717+
igraph_vector_int_push_back(result, vertexlike_to_igraph_int_t(u))
718+
igraph_vector_int_push_back(result, vertexlike_to_igraph_int_t(v))
719719
return result
720720

721721

@@ -738,7 +738,7 @@ def vertex_selector_to_igraph_vs_t(
738738
)
739739
return _VertexSelector.create_with(igraph_vs_vector_copy, indices)
740740
else:
741-
index = vertexlike_to_igraph_integer_t(selector) # type: ignore
741+
index = vertexlike_to_igraph_int_t(selector) # type: ignore
742742
return _VertexSelector.create_with(igraph_vs_1, index)
743743

744744

@@ -758,14 +758,14 @@ def vertex_colors_to_igraph_vector_int_t_view(
758758
return iterable_to_igraph_vector_int_t_view(colors)
759759

760760

761-
def vertex_qtys_to_igraph_vector_t(weights: Iterable[float], graph: Graph) -> _Vector:
761+
def vertex_qty_to_igraph_vector_t(weights: Iterable[float], graph: Graph) -> _Vector:
762762
"""Converts a Python iterable of floating-point numbers to a vector of
763763
vertex-related quantities.
764764
"""
765765
return iterable_to_igraph_vector_t(weights)
766766

767767

768-
def vertex_qtys_to_igraph_vector_t_view(
768+
def vertex_qty_to_igraph_vector_t_view(
769769
weights: Optional[Iterable[float]], graph: Graph
770770
) -> Optional[_Vector]:
771771
"""Converts a Python iterable of floating-point numbers to a vector of
@@ -830,7 +830,7 @@ def igraph_matrix_t_to_numpy_array(matrix: _Matrix) -> RealArray:
830830

831831
def igraph_matrix_int_t_to_numpy_array(matrix: _MatrixInt) -> IntArray:
832832
shape = igraph_matrix_int_nrow(matrix), igraph_matrix_int_ncol(matrix)
833-
result = np.zeros(shape, dtype=np_type_of_igraph_integer_t)
833+
result = np.zeros(shape, dtype=np_type_of_igraph_int_t)
834834
if result.size > 0:
835835
memmove(result.ctypes.data, matrix.unwrap().data.stor_begin, result.nbytes)
836836
return result
@@ -872,7 +872,7 @@ def igraph_vector_bool_t_to_numpy_array_view(vector: _VectorBool) -> BoolArray:
872872

873873
def igraph_vector_int_t_to_numpy_array(vector: _VectorInt) -> IntArray:
874874
n = igraph_vector_int_size(vector)
875-
result = np.zeros(n, dtype=np_type_of_igraph_integer_t)
875+
result = np.zeros(n, dtype=np_type_of_igraph_int_t)
876876
if n > 0:
877877
memmove(result.ctypes.data, igraph_vector_int_get_ptr(vector, 0), result.nbytes)
878878
return result
@@ -881,9 +881,9 @@ def igraph_vector_int_t_to_numpy_array(vector: _VectorInt) -> IntArray:
881881
def igraph_vector_int_t_to_numpy_array_view(vector: _VectorInt) -> IntArray:
882882
n = igraph_vector_int_size(vector)
883883
addr = addressof(igraph_vector_int_get_ptr(vector, 0).contents)
884-
buf_type = igraph_integer_t * n
884+
buf_type = igraph_int_t * n
885885
buf = buf_type.from_address(addr)
886-
return np.frombuffer(buf, dtype=np_type_of_igraph_integer_t)
886+
return np.frombuffer(buf, dtype=np_type_of_igraph_int_t)
887887

888888

889889
def igraph_vector_list_t_to_list_of_numpy_array(

0 commit comments

Comments
 (0)