1111 igraph_matrix_int_t_to_numpy_array ,
1212 igraph_vector_t_to_list ,
1313 igraph_vector_t_to_numpy_array ,
14+ igraph_vector_t_to_numpy_array_view ,
1415 igraph_vector_bool_t_to_list ,
1516 igraph_vector_bool_t_to_numpy_array ,
17+ igraph_vector_bool_t_to_numpy_array_view ,
1618 igraph_vector_int_t_to_list ,
1719 igraph_vector_int_t_to_numpy_array ,
20+ igraph_vector_int_t_to_numpy_array_view ,
1821 igraph_vector_int_list_t_to_list_of_numpy_array ,
1922 igraph_vector_list_t_to_list_of_numpy_array ,
2023 iterable_of_iterable_to_igraph_vector_list_t ,
@@ -94,6 +97,22 @@ def test_bool_vector_roundtrip():
9497 assert (restored_array == expected_array ).all ()
9598
9699
100+ def test_bool_vector_view_roundtrip ():
101+ input = [False , 0 , True , False , "" , "yes" , True ]
102+ expected = [bool (x ) for x in input ]
103+ expected_array = array (expected , dtype = bool )
104+
105+ converted = iterable_to_igraph_vector_bool_t (expected )
106+ assert isinstance (converted , _VectorBool )
107+
108+ restored = igraph_vector_bool_t_to_numpy_array_view (converted )
109+ assert (restored == expected_array ).all ()
110+
111+ another_restored = igraph_vector_bool_t_to_numpy_array_view (converted )
112+ assert (another_restored == expected_array ).all ()
113+ assert restored .data == another_restored .data
114+
115+
97116def test_int_vector_roundtrip ():
98117 input = [1 , 4 , 7 , 11 , 8 , 3 , 5 , 6 , 2 , - 6 ]
99118 expected = list (input )
@@ -115,6 +134,22 @@ def test_int_vector_roundtrip():
115134 assert (restored_array == expected_array ).all ()
116135
117136
137+ def test_int_vector_view_roundtrip ():
138+ input = [1 , 4 , 7 , 11 , 8 , 3 , 5 , 6 , 2 , - 6 ]
139+ expected = list (input )
140+ expected_array = array (expected )
141+
142+ converted = iterable_to_igraph_vector_int_t (expected )
143+ assert isinstance (converted , _VectorInt )
144+
145+ restored = igraph_vector_int_t_to_numpy_array_view (converted )
146+ assert (restored == expected_array ).all ()
147+
148+ another_restored = igraph_vector_int_t_to_numpy_array_view (converted )
149+ assert (another_restored == expected_array ).all ()
150+ assert restored .data == another_restored .data
151+
152+
118153def test_real_vector_roundtrip ():
119154 input = [1.23 , 4.567 , 8.91011 , - 12.3456 ]
120155 expected = list (input )
@@ -136,6 +171,22 @@ def test_real_vector_roundtrip():
136171 assert (restored_array == expected_array ).all ()
137172
138173
174+ def test_real_vector_view_roundtrip ():
175+ input = [1.23 , 4.567 , 8.91011 , - 12.3456 ]
176+ expected = list (input )
177+ expected_array = array (expected )
178+
179+ converted = iterable_to_igraph_vector_t (expected )
180+ assert isinstance (converted , _Vector )
181+
182+ restored = igraph_vector_t_to_numpy_array_view (converted )
183+ assert (restored == expected_array ).all ()
184+
185+ another_restored = igraph_vector_t_to_numpy_array_view (converted )
186+ assert (another_restored == expected_array ).all ()
187+ assert restored .data == another_restored .data
188+
189+
139190def test_int_matrix_roundtrip ():
140191 input = [
141192 [0 , 1 , 2 , 3 , 4 ],
@@ -196,7 +247,7 @@ def test_int_vector_list_roundtrip():
196247 restored_items = igraph_vector_int_list_t_to_list_of_numpy_array (converted )
197248 assert len (restored_items ) == len (input )
198249
199- for original_item , restored_item in zip (input , restored_items ):
250+ for original_item , restored_item in zip (input , restored_items , strict = True ):
200251 assert (array (original_item ) == restored_item ).all ()
201252
202253
@@ -214,12 +265,12 @@ def test_vector_list_roundtrip():
214265 restored_items = igraph_vector_list_t_to_list_of_numpy_array (converted )
215266 assert len (restored_items ) == len (input )
216267
217- for original_item , restored_item in zip (input , restored_items ):
268+ for original_item , restored_item in zip (input , restored_items , strict = True ):
218269 assert (array (original_item ) == restored_item ).all ()
219270
220271
221272def test_vertex_selector ():
222- g = create_empty_graph (5 ). _instance
273+ g = create_empty_graph (5 )
223274
224275 vs = vertex_selector_to_igraph_vs_t (None , g )
225276 assert vs .unwrap ().type == VertexSequenceType .NONE
@@ -246,7 +297,6 @@ def test_vertex_selector():
246297def test_edge_selector ():
247298 g = create_empty_graph (5 )
248299 g .add_edges ([(0 , 1 ), (1 , 2 ), (2 , 4 ), (4 , 0 )])
249- g = g ._instance
250300
251301 es = edge_selector_to_igraph_es_t (None , g )
252302 assert es .unwrap ().type == EdgeSequenceType .NONE
0 commit comments