Create an :class:`AdjacencyList` for `int32` or `int64` datasets. Args: data: The adjacency array. If the array is one-dimensional, offsets should be supplied. If the array is two-dimensional the number of edges per node is the second dimension. offsets:
(
data: npt.NDArray[Index], offsets: npt.NDArray[np.int32] | None = None
)
| 120 | |
| 121 | |
| 122 | def adjacencylist( |
| 123 | data: npt.NDArray[Index], offsets: npt.NDArray[np.int32] | None = None |
| 124 | ) -> AdjacencyList[Index]: |
| 125 | """Create an :class:`AdjacencyList` for `int32` or `int64` datasets. |
| 126 | |
| 127 | Args: |
| 128 | data: The adjacency array. If the array is one-dimensional, |
| 129 | offsets should be supplied. If the array is two-dimensional |
| 130 | the number of edges per node is the second dimension. |
| 131 | offsets: The offsets array with the number of edges per node. |
| 132 | |
| 133 | Returns: |
| 134 | An adjacency list. |
| 135 | """ |
| 136 | # TODO: Switch to np.isdtype(data.dtype, np.int32) once numpy >= 2.0 is |
| 137 | # enforced |
| 138 | if data.dtype == np.int32: |
| 139 | cpp_t = _cpp.graph.AdjacencyList_int32 |
| 140 | elif data.dtype == np.int64: |
| 141 | cpp_t = _cpp.graph.AdjacencyList_int64 |
| 142 | else: |
| 143 | raise TypeError("Data type for adjacency list not supported.") |
| 144 | |
| 145 | cpp_object = cpp_t(data, offsets) if offsets is not None else cpp_t(data) |
| 146 | return AdjacencyList(cpp_object) |
| 147 | |
| 148 | |
| 149 | def comm_graph(map: _cpp.common.IndexMap, root: int = 0) -> AdjacencyList: |