Commit f2d4b756 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

uncertain_blockmodel: avoid copying uentropy_args_t

parent d329acf4
...@@ -166,7 +166,7 @@ struct Dynamics ...@@ -166,7 +166,7 @@ struct Dynamics
return -S; return -S;
} }
double remove_edge_dS(size_t u, size_t v, uentropy_args_t ea) double remove_edge_dS(size_t u, size_t v, const uentropy_args_t& ea)
{ {
auto& e = get_u_edge(u, v); auto& e = get_u_edge(u, v);
auto x = _xc[e]; auto x = _xc[e];
...@@ -193,7 +193,7 @@ struct Dynamics ...@@ -193,7 +193,7 @@ struct Dynamics
return dS; return dS;
} }
double add_edge_dS(size_t u, size_t v, double x, uentropy_args_t ea) double add_edge_dS(size_t u, size_t v, double x, const uentropy_args_t& ea)
{ {
auto& e = get_u_edge(u, v); auto& e = get_u_edge(u, v);
double dS = _block_state.template modify_edge_dS<true>(u, v, e, double dS = _block_state.template modify_edge_dS<true>(u, v, e,
...@@ -216,7 +216,7 @@ struct Dynamics ...@@ -216,7 +216,7 @@ struct Dynamics
return dS; return dS;
} }
double update_edge_dS(size_t u, size_t v, double dx, uentropy_args_t ea) double update_edge_dS(size_t u, size_t v, double dx, const uentropy_args_t& ea)
{ {
double dS = 0; double dS = 0;
if (ea.latent_edges) if (ea.latent_edges)
......
...@@ -88,14 +88,14 @@ void export_cising_glauber_state() ...@@ -88,14 +88,14 @@ void export_cising_glauber_state()
.def("get_node_prob", &state_t::get_node_prob) .def("get_node_prob", &state_t::get_node_prob)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, double x, +[](state_t& state, size_t u, size_t v, double x,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon, x); epsilon, x);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_xedges_prob(state, edges, probs, ea, get_xedges_prob(state, edges, probs, ea,
......
...@@ -88,14 +88,14 @@ void export_epidemics_state() ...@@ -88,14 +88,14 @@ void export_epidemics_state()
.def("get_node_prob", &state_t::get_node_prob) .def("get_node_prob", &state_t::get_node_prob)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, double x, +[](state_t& state, size_t u, size_t v, double x,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon, x); epsilon, x);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_xedges_prob(state, edges, probs, ea, get_xedges_prob(state, edges, probs, ea,
......
...@@ -88,14 +88,14 @@ void export_ising_glauber_state() ...@@ -88,14 +88,14 @@ void export_ising_glauber_state()
.def("get_node_prob", &state_t::get_node_prob) .def("get_node_prob", &state_t::get_node_prob)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, double x, +[](state_t& state, size_t u, size_t v, double x,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon, x); epsilon, x);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_xedges_prob(state, edges, probs, ea, get_xedges_prob(state, edges, probs, ea,
......
...@@ -87,14 +87,14 @@ void export_pseudo_cising_state() ...@@ -87,14 +87,14 @@ void export_pseudo_cising_state()
.def("get_node_prob", &state_t::get_node_prob) .def("get_node_prob", &state_t::get_node_prob)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, double x, +[](state_t& state, size_t u, size_t v, double x,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon, x); epsilon, x);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_xedges_prob(state, edges, probs, ea, get_xedges_prob(state, edges, probs, ea,
......
...@@ -87,14 +87,14 @@ void export_pseudo_ising_state() ...@@ -87,14 +87,14 @@ void export_pseudo_ising_state()
.def("get_node_prob", &state_t::get_node_prob) .def("get_node_prob", &state_t::get_node_prob)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, double x, +[](state_t& state, size_t u, size_t v, double x,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon, x); epsilon, x);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_xedges_prob(state, edges, probs, ea, get_xedges_prob(state, edges, probs, ea,
......
...@@ -79,6 +79,18 @@ void export_measured_state() ...@@ -79,6 +79,18 @@ void export_measured_state()
no_init); no_init);
c.def("remove_edge", &state_t::remove_edge) c.def("remove_edge", &state_t::remove_edge)
.def("add_edge", &state_t::add_edge) .def("add_edge", &state_t::add_edge)
.def("set_state",
+[](state_t& state, GraphInterface& gi,
boost::any aw)
{
typedef eprop_map_t<int32_t>::type emap_t;
auto w = any_cast<emap_t>(aw).get_unchecked();
gt_dispatch<>()
([&](auto& g)
{ set_state(state, g, w); },
all_graph_views())
(gi.get_graph_view());
})
.def("remove_edge_dS", &state_t::remove_edge_dS) .def("remove_edge_dS", &state_t::remove_edge_dS)
.def("add_edge_dS", &state_t::add_edge_dS) .def("add_edge_dS", &state_t::add_edge_dS)
.def("entropy", &state_t::entropy) .def("entropy", &state_t::entropy)
...@@ -89,14 +101,14 @@ void export_measured_state() ...@@ -89,14 +101,14 @@ void export_measured_state()
.def("get_M", &state_t::get_M) .def("get_M", &state_t::get_M)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, +[](state_t& state, size_t u, size_t v,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon); epsilon);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_edges_prob(state, edges, probs, ea, get_edges_prob(state, edges, probs, ea,
......
...@@ -209,7 +209,7 @@ struct Measured ...@@ -209,7 +209,7 @@ struct Measured
return -(Sf - Si); return -(Sf - Si);
} }
double remove_edge_dS(size_t u, size_t v, uentropy_args_t ea) double remove_edge_dS(size_t u, size_t v, const uentropy_args_t& ea)
{ {
auto& e = get_u_edge(u, v); auto& e = get_u_edge(u, v);
double dS = _block_state.template modify_edge_dS<false>(source(e, _u), double dS = _block_state.template modify_edge_dS<false>(source(e, _u),
...@@ -235,7 +235,7 @@ struct Measured ...@@ -235,7 +235,7 @@ struct Measured
return dS; return dS;
} }
double add_edge_dS(size_t u, size_t v, uentropy_args_t ea) double add_edge_dS(size_t u, size_t v, const uentropy_args_t& ea)
{ {
auto& e = get_u_edge(u, v); auto& e = get_u_edge(u, v);
double dS = _block_state.template modify_edge_dS<true>(u, v, e, double dS = _block_state.template modify_edge_dS<true>(u, v, e,
......
...@@ -120,14 +120,14 @@ void export_uncertain_state() ...@@ -120,14 +120,14 @@ void export_uncertain_state()
.def("set_S_const", &state_t::set_S_const) .def("set_S_const", &state_t::set_S_const)
.def("get_edge_prob", .def("get_edge_prob",
+[](state_t& state, size_t u, size_t v, +[](state_t& state, size_t u, size_t v,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
return get_edge_prob(state, u, v, ea, return get_edge_prob(state, u, v, ea,
epsilon); epsilon);
}) })
.def("get_edges_prob", .def("get_edges_prob",
+[](state_t& state, python::object edges, +[](state_t& state, python::object edges,
python::object probs, uentropy_args_t ea, python::object probs, const uentropy_args_t& ea,
double epsilon) double epsilon)
{ {
get_edges_prob(state, edges, probs, ea, get_edges_prob(state, edges, probs, ea,
......
...@@ -168,7 +168,7 @@ struct Uncertain ...@@ -168,7 +168,7 @@ struct Uncertain
return -S; return -S;
} }
double remove_edge_dS(size_t u, size_t v, uentropy_args_t ea) double remove_edge_dS(size_t u, size_t v, const uentropy_args_t& ea)
{ {
auto& e = get_u_edge(u, v); auto& e = get_u_edge(u, v);
double dS = _block_state.template modify_edge_dS<false>(source(e, _u), double dS = _block_state.template modify_edge_dS<false>(source(e, _u),
...@@ -192,7 +192,7 @@ struct Uncertain ...@@ -192,7 +192,7 @@ struct Uncertain
return dS; return dS;
} }
double add_edge_dS(size_t u, size_t v, uentropy_args_t ea) double add_edge_dS(size_t u, size_t v, const uentropy_args_t& ea)
{ {
auto& e = get_u_edge(u, v); auto& e = get_u_edge(u, v);
double dS = _block_state.template modify_edge_dS<true>(u, v, e, double dS = _block_state.template modify_edge_dS<true>(u, v, e,
......
...@@ -31,7 +31,7 @@ T logsum(T a, T b) ...@@ -31,7 +31,7 @@ T logsum(T a, T b)
} }
template <class State, class... X> template <class State, class... X>
double get_edge_prob(State& state, size_t u, size_t v, uentropy_args_t ea, double get_edge_prob(State& state, size_t u, size_t v, const uentropy_args_t& ea,
double epsilon, X... x) double epsilon, X... x)
{ {
auto e = state.get_u_edge(u, v); auto e = state.get_u_edge(u, v);
...@@ -77,7 +77,7 @@ double get_edge_prob(State& state, size_t u, size_t v, uentropy_args_t ea, ...@@ -77,7 +77,7 @@ double get_edge_prob(State& state, size_t u, size_t v, uentropy_args_t ea,
template <class State> template <class State>
void get_edges_prob(State& state, python::object edges, python::object probs, void get_edges_prob(State& state, python::object edges, python::object probs,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
multi_array_ref<uint64_t,2> es = get_array<uint64_t,2>(edges); multi_array_ref<uint64_t,2> es = get_array<uint64_t,2>(edges);
multi_array_ref<double,1> eprobs = get_array<double,1>(probs); multi_array_ref<double,1> eprobs = get_array<double,1>(probs);
...@@ -87,7 +87,7 @@ void get_edges_prob(State& state, python::object edges, python::object probs, ...@@ -87,7 +87,7 @@ void get_edges_prob(State& state, python::object edges, python::object probs,
template <class State> template <class State>
void get_xedges_prob(State& state, python::object edges, python::object probs, void get_xedges_prob(State& state, python::object edges, python::object probs,
uentropy_args_t ea, double epsilon) const uentropy_args_t& ea, double epsilon)
{ {
multi_array_ref<double,2> es = get_array<double,2>(edges); multi_array_ref<double,2> es = get_array<double,2>(edges);
multi_array_ref<double,1> eprobs = get_array<double,1>(probs); multi_array_ref<double,1> eprobs = get_array<double,1>(probs);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment