|
6 | 6 | from dataclasses import dataclass, field |
7 | 7 | from typing import Any, Callable, Optional |
8 | 8 |
|
9 | | -from .lib import igraph_error, igraph_vector_ptr_size |
| 9 | +from .conversion import igraph_vector_int_t_to_numpy_array_view |
| 10 | +from .lib import igraph_error |
10 | 11 | from .refcount import incref, decref |
11 | | -from .types import igraph_attribute_table_t |
| 12 | +from .types import igraph_attribute_table_t, IntArray |
12 | 13 | from .utils import nop, protect_with |
13 | 14 |
|
14 | 15 | __all__ = ("AttributeHandlerBase", "AttributeHandler", "AttributeStorage") |
@@ -66,6 +67,13 @@ def add_vertices(self, graph, n: int) -> None: |
66 | 67 | """ |
67 | 68 | raise NotImplementedError |
68 | 69 |
|
| 70 | + @abstractmethod |
| 71 | + def add_edges(self, graph, edges) -> None: |
| 72 | + """Notifies the attribute storage object that the given edges were |
| 73 | + added to the graph. |
| 74 | + """ |
| 75 | + raise NotImplementedError |
| 76 | + |
69 | 77 | @abstractmethod |
70 | 78 | def clear(self): |
71 | 79 | """Clears the storage area, removing all attributes.""" |
@@ -94,6 +102,9 @@ class DictAttributeStorage(AttributeStorage): |
94 | 102 | def add_vertices(self, graph, n: int) -> None: |
95 | 103 | pass |
96 | 104 |
|
| 105 | + def add_edges(self, graph, edges: IntArray) -> None: |
| 106 | + pass |
| 107 | + |
97 | 108 | def clear(self) -> None: |
98 | 109 | """Clears the storage area, removing all attributes from the |
99 | 110 | attribute dictionaries. |
@@ -194,7 +205,16 @@ def combine_vertices(self, graph, to, mapping, combinations): |
194 | 205 | pass |
195 | 206 |
|
196 | 207 | def add_edges(self, graph, edges, attr) -> None: |
197 | | - pass |
| 208 | + # attr will only ever be NULL here so raise an error if it is not |
| 209 | + if attr: |
| 210 | + raise RuntimeError( |
| 211 | + "add_edges() attribute handler called with non-null attr; " |
| 212 | + "this is most likely a bug" |
| 213 | + ) |
| 214 | + |
| 215 | + # Extend the existing attribute containers |
| 216 | + edge_array = igraph_vector_int_t_to_numpy_array_view(edges).reshape((-1, 2)) |
| 217 | + _get_storage_from_graph(graph).add_edges(graph, edge_array) |
198 | 218 |
|
199 | 219 | def permute_edges(self, graph, to, mapping): |
200 | 220 | pass |
|
0 commit comments