Skip to content

Commit 27c3f06

Browse files
committed
feat: added igraph_attribute_table_t
1 parent a3f2c4c commit 27c3f06

File tree

8 files changed

+223
-12
lines changed

8 files changed

+223
-12
lines changed

src/codegen/internal_lib.py.in

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from ctypes import cdll, c_bool, c_char_p, c_double, c_int, c_void_p, POINTER
1010
from ctypes.util import find_library
1111

12+
from .attributes import (
13+
igraph_attribute_combination_t,
14+
igraph_attribute_table_t,
15+
)
1216
from .errors import handle_igraph_error_t
1317
from .types import (
1418
FILE,
15-
igraph_attribute_combination_t,
1619
igraph_bool_t,
1720
igraph_integer_t,
1821
igraph_real_t,
@@ -167,6 +170,16 @@ igraph_vector_bool_size = _lib.igraph_vector_bool_size
167170
igraph_vector_bool_size.restype = igraph_integer_t
168171
igraph_vector_bool_size.argtypes = [POINTER(igraph_vector_bool_t)]
169172

173+
# Pointer vector type
174+
175+
igraph_vector_ptr_init = _lib.igraph_vector_ptr_init
176+
igraph_vector_ptr_init.restype = handle_igraph_error_t
177+
igraph_vector_ptr_init.argtypes = [POINTER(igraph_vector_ptr_t), igraph_integer_t]
178+
179+
igraph_vector_ptr_destroy = _lib.igraph_vector_ptr_destroy
180+
igraph_vector_ptr_destroy.restype = None
181+
igraph_vector_ptr_destroy.argtypes = [c_void_p]
182+
170183
# Matrix type
171184

172185
igraph_matrix_init = _lib.igraph_matrix_init
@@ -384,6 +397,16 @@ igraph_destroy = _lib.igraph_destroy
384397
igraph_destroy.restype = None
385398
igraph_destroy.argtypes = [POINTER(igraph_t)]
386399

400+
# Attributes
401+
402+
igraph_has_attribute_table = _lib.igraph_has_attribute_table
403+
igraph_has_attribute_table.restype = igraph_bool_t
404+
igraph_has_attribute_table.argtypes = []
405+
406+
igraph_set_attribute_table = _lib.igraph_set_attribute_table
407+
igraph_set_attribute_table.restype = POINTER(igraph_attribute_table_t)
408+
igraph_set_attribute_table.argtypes = [POINTER(igraph_attribute_table_t)]
409+
387410
# Error handling and interruptions
388411

389412
igraph_set_error_handler = _lib.igraph_set_error_handler

src/codegen/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,11 @@ def generate_enums( # noqa: C901
114114

115115
IGNORED_ENUMS = {
116116
"igraph_cached_property_t",
117-
"igraph_attribute_type_t",
118-
"igraph_attribute_elemtype_t",
119117
"igraph_lapack_dsyev_which_t",
120118
}
121119
ENUM_NAME_REMAPPING = {
122120
"Adjacency": "AdjacencyMode",
121+
"AttributeElemtype": "AttributeElementType",
123122
"BlissSh": "BLISSSplittingHeuristics",
124123
"Degseq": "DegreeSequenceMode",
125124
"EdgeorderType": "EdgeOrder",
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
from ctypes import c_char_p, c_int, c_void_p, CFUNCTYPE, POINTER, Structure
2+
3+
from .types import (
4+
igraph_bool_t,
5+
igraph_error_t,
6+
igraph_es_t,
7+
igraph_integer_t,
8+
igraph_strvector_t,
9+
igraph_t,
10+
igraph_vector_bool_t,
11+
igraph_vector_int_t,
12+
igraph_vector_int_list_t,
13+
igraph_vector_ptr_t,
14+
igraph_vector_t,
15+
igraph_vs_t,
16+
)
17+
18+
19+
p_igraph_t = POINTER(igraph_t)
20+
p_strvector_t = POINTER(igraph_strvector_t)
21+
p_vector_t = POINTER(igraph_vector_t)
22+
p_vector_bool_t = POINTER(igraph_vector_bool_t)
23+
p_vector_int_t = POINTER(igraph_vector_int_t)
24+
p_vector_int_list_t = POINTER(igraph_vector_int_list_t)
25+
p_vector_ptr_t = POINTER(igraph_vector_ptr_t)
26+
27+
28+
class igraph_attribute_combination_t(Structure):
29+
"""ctypes representation of ``igraph_attribute_combination_t``"""
30+
31+
_fields_ = [("list", igraph_vector_ptr_t)]
32+
33+
34+
class igraph_attribute_combination_record_t(Structure):
35+
"""ctypes representation of ``igraph_attribute_combination_record_t``"""
36+
37+
_fields_ = [("name", c_char_p), ("type", c_int), ("func", CFUNCTYPE(c_void_p))]
38+
39+
40+
p_attribute_combination_t = POINTER(igraph_attribute_combination_t)
41+
42+
43+
class igraph_attribute_table_t(Structure):
44+
"""ctypes representation of ``igraph_attribute_table_t``"""
45+
46+
TYPES = {
47+
"init": CFUNCTYPE(igraph_error_t, p_igraph_t, p_vector_ptr_t),
48+
"destroy": CFUNCTYPE(None, p_igraph_t),
49+
"copy": CFUNCTYPE(
50+
igraph_error_t,
51+
p_igraph_t,
52+
p_igraph_t,
53+
igraph_bool_t,
54+
igraph_bool_t,
55+
igraph_bool_t,
56+
),
57+
"add_vertices": CFUNCTYPE(
58+
igraph_error_t, p_igraph_t, igraph_integer_t, p_vector_ptr_t
59+
),
60+
"permute_vertices": CFUNCTYPE(
61+
igraph_error_t, p_igraph_t, p_igraph_t, p_vector_int_t
62+
),
63+
"combine_vertices": CFUNCTYPE(
64+
igraph_error_t,
65+
p_igraph_t,
66+
p_igraph_t,
67+
p_vector_int_list_t,
68+
p_attribute_combination_t,
69+
),
70+
"add_edges": CFUNCTYPE(
71+
igraph_error_t, p_igraph_t, p_vector_int_t, p_vector_ptr_t
72+
),
73+
"permute_edges": CFUNCTYPE(
74+
igraph_error_t, p_igraph_t, p_igraph_t, p_vector_int_t
75+
),
76+
"combine_edges": CFUNCTYPE(
77+
igraph_error_t,
78+
p_igraph_t,
79+
p_igraph_t,
80+
p_vector_int_list_t,
81+
p_attribute_combination_t,
82+
),
83+
"get_info": CFUNCTYPE(
84+
igraph_error_t,
85+
p_igraph_t,
86+
p_strvector_t,
87+
p_vector_int_t,
88+
p_strvector_t,
89+
p_vector_int_t,
90+
p_strvector_t,
91+
p_vector_int_t,
92+
),
93+
"has_attr": CFUNCTYPE(igraph_bool_t, p_igraph_t, c_int, c_char_p),
94+
"get_type": CFUNCTYPE(
95+
igraph_error_t, p_igraph_t, POINTER(c_int), c_int, c_char_p
96+
),
97+
"get_numeric_graph_attr": CFUNCTYPE(p_igraph_t, c_char_p, p_vector_t),
98+
"get_string_graph_attr": CFUNCTYPE(p_igraph_t, c_char_p, p_strvector_t),
99+
"get_bool_graph_attr": CFUNCTYPE(p_igraph_t, c_char_p, p_vector_bool_t),
100+
"get_numeric_vertex_attr": CFUNCTYPE(
101+
p_igraph_t, c_char_p, igraph_vs_t, p_vector_t
102+
),
103+
"get_string_vertex_attr": CFUNCTYPE(
104+
p_igraph_t, c_char_p, igraph_vs_t, p_strvector_t
105+
),
106+
"get_bool_vertex_attr": CFUNCTYPE(
107+
p_igraph_t, c_char_p, igraph_vs_t, p_vector_bool_t
108+
),
109+
"get_numeric_edge_attr": CFUNCTYPE(
110+
p_igraph_t, c_char_p, igraph_es_t, p_vector_t
111+
),
112+
"get_string_edge_attr": CFUNCTYPE(
113+
p_igraph_t, c_char_p, igraph_es_t, p_strvector_t
114+
),
115+
"get_bool_edge_attr": CFUNCTYPE(
116+
p_igraph_t, c_char_p, igraph_es_t, p_vector_bool_t
117+
),
118+
}
119+
120+
_fields_ = [
121+
("init", TYPES["init"]),
122+
("destroy", TYPES["destroy"]),
123+
("copy", TYPES["copy"]),
124+
("add_vertices", TYPES["add_vertices"]),
125+
("permute_vertices", TYPES["permute_vertices"]),
126+
("combine_vertices", TYPES["combine_vertices"]),
127+
("add_edges", TYPES["add_edges"]),
128+
("permute_edges", TYPES["permute_edges"]),
129+
("combine_edges", TYPES["combine_edges"]),
130+
("get_info", TYPES["get_info"]),
131+
("has_attr", TYPES["has_attr"]),
132+
("get_numeric_graph_attr", TYPES["get_numeric_graph_attr"]),
133+
("get_string_graph_attr", TYPES["get_string_graph_attr"]),
134+
("get_bool_graph_attr", TYPES["get_bool_graph_attr"]),
135+
("get_numeric_vertex_attr", TYPES["get_numeric_vertex_attr"]),
136+
("get_string_vertex_attr", TYPES["get_string_vertex_attr"]),
137+
("get_bool_vertex_attr", TYPES["get_bool_vertex_attr"]),
138+
("get_numeric_edge_attr", TYPES["get_numeric_edge_attr"]),
139+
("get_string_edge_attr", TYPES["get_string_edge_attr"]),
140+
("get_bool_edge_attr", TYPES["get_bool_edge_attr"]),
141+
]

src/igraph_ctypes/_internal/enums.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ class Loops(IntEnum):
1111

1212
# fmt: off
1313
# The rest of this file is generated
14+
class AttributeType(IntEnum):
15+
"""Python counterpart of an ``igraph_attribute_type_t`` enum."""
16+
17+
UNSPECIFIED = 0
18+
NUMERIC = 1
19+
BOOLEAN = 2
20+
STRING = 3
21+
OBJECT = 127
22+
23+
24+
class AttributeElementType(IntEnum):
25+
"""Python counterpart of an ``igraph_attribute_elemtype_t`` enum."""
26+
27+
GRAPH = 0
28+
VERTEX = 1
29+
EDGE = 2
30+
31+
1432
class AttributeCombinationType(IntEnum):
1533
"""Python counterpart of an ``igraph_attribute_combination_type_t`` enum."""
1634

@@ -527,6 +545,8 @@ class LeadingEigenvectorCommunityHistory(IntEnum):
527545
'AddWeights',
528546
'AdjacencyMode',
529547
'AttributeCombinationType',
548+
'AttributeElementType',
549+
'AttributeType',
530550
'BLISSSplittingHeuristics',
531551
'BarabasiAlgorithm',
532552
'ColoringGreedy',

src/igraph_ctypes/_internal/lib.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from ctypes import cdll, c_bool, c_char_p, c_double, c_int, c_void_p, POINTER
1010
from ctypes.util import find_library
1111

12+
from .attributes import (
13+
igraph_attribute_combination_t,
14+
igraph_attribute_table_t,
15+
)
1216
from .errors import handle_igraph_error_t
1317
from .types import (
1418
FILE,
15-
igraph_attribute_combination_t,
1619
igraph_bool_t,
1720
igraph_integer_t,
1821
igraph_real_t,
@@ -167,6 +170,16 @@ def _load_igraph_c_library():
167170
igraph_vector_bool_size.restype = igraph_integer_t
168171
igraph_vector_bool_size.argtypes = [POINTER(igraph_vector_bool_t)]
169172

173+
# Pointer vector type
174+
175+
igraph_vector_ptr_init = _lib.igraph_vector_ptr_init
176+
igraph_vector_ptr_init.restype = handle_igraph_error_t
177+
igraph_vector_ptr_init.argtypes = [POINTER(igraph_vector_ptr_t), igraph_integer_t]
178+
179+
igraph_vector_ptr_destroy = _lib.igraph_vector_ptr_destroy
180+
igraph_vector_ptr_destroy.restype = None
181+
igraph_vector_ptr_destroy.argtypes = [c_void_p]
182+
170183
# Matrix type
171184

172185
igraph_matrix_init = _lib.igraph_matrix_init
@@ -384,6 +397,16 @@ def _load_igraph_c_library():
384397
igraph_destroy.restype = None
385398
igraph_destroy.argtypes = [POINTER(igraph_t)]
386399

400+
# Attributes
401+
402+
igraph_has_attribute_table = _lib.igraph_has_attribute_table
403+
igraph_has_attribute_table.restype = igraph_bool_t
404+
igraph_has_attribute_table.argtypes = []
405+
406+
igraph_set_attribute_table = _lib.igraph_set_attribute_table
407+
igraph_set_attribute_table.restype = POINTER(igraph_attribute_table_t)
408+
igraph_set_attribute_table.argtypes = [POINTER(igraph_attribute_table_t)]
409+
387410
# Error handling and interruptions
388411

389412
igraph_set_error_handler = _lib.igraph_set_error_handler

src/igraph_ctypes/_internal/types.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
c_uint8,
1414
c_uint64,
1515
c_void_p,
16-
py_object,
1716
POINTER,
1817
Structure,
1918
Union as CUnion,
2019
)
2120
from typing import Iterable, Literal, Sequence, Tuple, Union
2221

23-
2422
def vector_fields(base_type):
2523
"""Function that receives a base type and returns the standard fields used
2624
in igraph for _vectors_ of the given ctypes base type.
@@ -166,12 +164,6 @@ class igraph_inclist_t(Structure):
166164
_fields_ = [("length", igraph_integer_t), ("incs", POINTER(igraph_vector_int_t))]
167165

168166

169-
class igraph_attribute_combination_t(Structure):
170-
"""ctypes representation of ``igraph_attribute_combination_t``"""
171-
172-
_fields_ = [("list", igraph_vector_ptr_t)]
173-
174-
175167
class igraph_t(Structure):
176168
"""ctypes representation of ``igraph_t``"""
177169

src/igraph_ctypes/_internal/wrappers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
igraph_vector_int_list_init,
3232
igraph_vector_list_destroy,
3333
igraph_vector_list_init,
34+
igraph_vector_ptr_destroy,
35+
igraph_vector_ptr_init,
3436
igraph_vs_destroy,
3537
)
3638
from .types import (
@@ -44,6 +46,7 @@
4446
igraph_vector_int_t,
4547
igraph_vector_int_list_t,
4648
igraph_vector_list_t,
49+
igraph_vector_ptr_t,
4750
igraph_vs_t,
4851
)
4952

@@ -245,6 +248,12 @@ class _Graph(create_boxed("_Graph", igraph_t, destructor=igraph_destroy)):
245248
constructor=igraph_vector_list_init,
246249
destructor=igraph_vector_list_destroy,
247250
)
251+
_VectorPtr = create_boxed(
252+
"_VectorPtr",
253+
igraph_vector_ptr_t,
254+
constructor=igraph_vector_ptr_init,
255+
destructor=igraph_vector_ptr_destroy,
256+
)
248257
_VertexSelector = create_boxed(
249258
"_VertexSelector",
250259
igraph_vs_t,

src/igraph_ctypes/enums.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
AddWeights,
1010
AdjacencyMode,
1111
AttributeCombinationType,
12+
AttributeElementType,
13+
AttributeType,
1214
BLISSSplittingHeuristics,
1315
BarabasiAlgorithm,
1416
ColoringGreedy,
@@ -66,6 +68,8 @@
6668
"AddWeights",
6769
"AdjacencyMode",
6870
"AttributeCombinationType",
71+
"AttributeElementType",
72+
"AttributeType",
6973
"BLISSSplittingHeuristics",
7074
"BarabasiAlgorithm",
7175
"ColoringGreedy",

0 commit comments

Comments
 (0)