forked from networkgeometry/mercator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_bind.cpp
116 lines (94 loc) · 2.62 KB
/
python_bind.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "../include/embeddingS1.hpp"
#include <pybind11/pybind11.h>
void embed(std::string edgelist_filename, std::string rootname_output, std::string already_inferred_parameters_filename, bool fast_mode, bool screen_mode, bool post_kappa, bool quiet_mode, bool validation_mode, bool clean_mode, int seed, double beta)
{
// Initialize graph object.
embeddingS1_t the_graph;
// Sets the edgelist filename.
the_graph.EDGELIST_FILENAME = edgelist_filename;
// Sets the output rootname.
if(rootname_output.length() != 0)
{
the_graph.CUSTOM_OUTPUT_ROOTNAME_MODE = true;
the_graph.ROOTNAME_OUTPUT = rootname_output;
}
// Activates the refine mode.
if(already_inferred_parameters_filename.length() != 0)
{
the_graph.REFINE_MODE = true;
the_graph.ALREADY_INFERRED_PARAMETERS_FILENAME = already_inferred_parameters_filename;
}
// Activates the fast mode.
if(fast_mode)
{
the_graph.MAXIMIZATION_MODE = false;
}
// Activates the validation mode.
if(validation_mode)
{
the_graph.VALIDATION_MODE = true;
the_graph.CHARACTERIZATION_MODE = true;
}
// Deactivates the post-processing of kappas.
if(!post_kappa)
{
the_graph.KAPPA_POST_INFERENCE_MODE = false;
}
// Activates the quiet mode.
if(quiet_mode)
{
the_graph.QUIET_MODE = true;
}
// Activates the clean mode.
if(clean_mode)
{
the_graph.CLEAN_RAW_OUTPUT_MODE = true;
}
// Activates the verbose mode.
if(screen_mode)
{
the_graph.VERBOSE_MODE = true;
}
// Sets a custom seed, if required.
if(seed != -1)
{
the_graph.CUSTOM_SEED = true;
the_graph.SEED = seed;
}
// Sets a custom value of beta, if required.
if(beta != -1)
{
the_graph.CUSTOM_BETA = true;
the_graph.beta = beta;
}
// Performs the embedding.
the_graph.embed();
}
namespace py = pybind11;
PYBIND11_MODULE(mercator, m) {
m.doc() = R"pbdoc(
Pybind11 example plugin
-----------------------
.. currentmodule:: python_example
.. autosummary::
:toctree: _generate
embed
)pbdoc";
m.def("embed", &embed, "",
py::arg("edgelist_filename"),
py::arg("output_name") = "",
py::arg("inf_coord") = "",
py::arg("fast_mode") = false,
py::arg("screen_mode") = false,
py::arg("post_kappa") = true,
py::arg("quiet_mode") = false,
py::arg("validation_mode") = false,
py::arg("clean_mode") = false,
py::arg("seed") = -1,
py::arg("beta") = -1);
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}