| 117 | |
| 118 | template<class... Args> |
| 119 | pyGraph(py::handle scope, const char *name, const Args &...args) : |
| 120 | Base(scope, signature(name, typeid(Index).name()).c_str(), args...) { |
| 121 | attr("__doc__") = "Graph(index_type=dtype.uint32)" |
| 122 | R"( |
| 123 | Normal graphs without attributes. |
| 124 | |
| 125 | Parameters: |
| 126 | index_type (dtype): type of node indexes |
| 127 | )"; |
| 128 | |
| 129 | // override instance name with template name |
| 130 | attr("__name__") = py::internal_str(name); |
| 131 | attr("__qualname__") = py::internal_str(name); |
| 132 | |
| 133 | // data members |
| 134 | def_readonly("num_vertex", &Graph::num_vertex); |
| 135 | def_readonly("num_edge", &Graph::num_edge); |
| 136 | def_readonly("as_undirected", &Graph::as_undirected); |
| 137 | def_readonly("normalization", &Graph::normalization); |
| 138 | def_readonly("name2id", &Graph::name2id, "Map of node name to index."); |
| 139 | def_readonly("id2name", &Graph::id2name, "Map of node index to name."); |
| 140 | |
| 141 | // member functions |
| 142 | def(py::init<>(), py::no_gil()); |
| 143 | |
| 144 | def("load", &Graph::load_file, py::no_gil(), |
| 145 | py::arg("file_name"), py::arg("as_undirected") = true, py::arg("normalization") = false, |
| 146 | py::arg("delimiters") = " \t\r\n", py::arg("comment") = "#", |
| 147 | "load(*args, **kwargs)" |
| 148 | R"( |
| 149 | Load a graph from an edge-list file. Store the graph in an adjacency list. |
| 150 | |
| 151 | This function has 3 overloads |
| 152 | |
| 153 | .. function:: load(file_name, as_undirected=True, normalization=False, delimiters=' \\t\\r\\n', comment='#') |
| 154 | .. function:: load(edge_list, as_undirected=True, normalization=False) |
| 155 | .. function:: load(weighted_edge_list, as_undirected=True, normalization=False) |
| 156 | |
| 157 | Parameters: |
| 158 | file_name (str): file name |
| 159 | edge_list (list of (str, str)): edge list |
| 160 | weighted_edge_list (list of (str, str, float)): weighted edge list |
| 161 | as_undirected (bool, optional): symmetrize the graph or not |
| 162 | normalization (bool, optional): normalize the adjacency matrix or not |
| 163 | delimiters (str, optional): string of delimiter characters |
| 164 | comment (str, optional): prefix of comment strings |
| 165 | )"); |
| 166 | |
| 167 | def("load", &Graph::load_edge_list, py::no_gil(), |
| 168 | py::arg("edge_list"), py::arg("as_undirected") = true, py::arg("normalization") = false); |
| 169 | |
| 170 | def("load", &Graph::load_weighted_edge_list, py::no_gil(), |
| 171 | py::arg("weighted_edge_list"), py::arg("as_undirected") = true, py::arg("normalization") = false); |
| 172 | |
| 173 | def("save", &Graph::save, py::no_gil(), |
| 174 | py::arg("file_name"), py::arg("weighted") = true, py::arg("anonymous") = false, |
| 175 | "save(file_name, weighted=True, anonymous=False)" |
| 176 | R"( |