Commit 51671878 authored by Tiago Peixoto's avatar Tiago Peixoto

inference: split units to improve memory usage during compilation

parent e1c811ad
......@@ -18,10 +18,12 @@ libgraph_tool_inference_la_SOURCES = \
cache.cc \
graph_blockmodel.cc \
graph_blockmodel_imp.cc \
graph_blockmodel_imp2.cc \
graph_blockmodel_em.cc \
graph_blockmodel_exhaustive.cc \
graph_blockmodel_gibbs.cc \
graph_blockmodel_layers.cc \
graph_blockmodel_layers_imp.cc \
graph_blockmodel_layers_exhaustive.cc \
graph_blockmodel_layers_gibbs.cc \
graph_blockmodel_layers_mcmc.cc \
......
......@@ -142,75 +142,13 @@ simple_degs_t copy_simple_degs(simple_degs_t& degs)
return degs;
}
void export_sbm_state();
void export_blockmodel_state()
{
using namespace boost::python;
block_state::dispatch
([&](auto* s)
{
typedef typename std::remove_reference<decltype(*s)>::type state_t;
void (state_t::*remove_vertex)(size_t) =
&state_t::remove_vertex;
void (state_t::*add_vertex)(size_t, size_t) =
&state_t::add_vertex;
void (state_t::*move_vertex)(size_t, size_t) =
&state_t::move_vertex;
void (state_t::*remove_vertices)(python::object) =
&state_t::remove_vertices;
void (state_t::*add_vertices)(python::object, python::object) =
&state_t::add_vertices;
void (state_t::*move_vertices)(python::object, python::object) =
&state_t::move_vertices;
double (state_t::*virtual_move)(size_t, size_t, size_t,
entropy_args_t) =
&state_t::virtual_move;
size_t (state_t::*sample_block)(size_t, double, rng_t&) =
&state_t::sample_block;
size_t (state_t::*random_neighbour)(size_t, rng_t&) =
&state_t::random_neighbour;
double (state_t::*get_move_prob)(size_t, size_t, size_t, double,
bool) =
&state_t::get_move_prob;
void (state_t::*merge_vertices)(size_t, size_t) =
&state_t::merge_vertices;
void (state_t::*set_partition)(boost::any&) =
&state_t::set_partition;
class_<state_t> c(name_demangle(typeid(state_t).name()).c_str(),
no_init);
c.def("remove_vertex", remove_vertex)
.def("add_vertex", add_vertex)
.def("remove_vertices", remove_vertices)
.def("add_vertices", add_vertices)
.def("move_vertex", move_vertex)
.def("move_vertices", move_vertices)
.def("set_partition", set_partition)
.def("virtual_move", virtual_move)
.def("merge_vertices", merge_vertices)
.def("sample_block", sample_block)
.def("sample_neighbour", random_neighbour)
.def("entropy", &state_t::entropy)
.def("get_partition_dl", &state_t::get_partition_dl)
.def("get_deg_dl", &state_t::get_deg_dl)
.def("get_move_prob", get_move_prob)
.def("enable_partition_stats",
&state_t::enable_partition_stats)
.def("disable_partition_stats",
&state_t::disable_partition_stats)
.def("is_partition_stats_enabled",
&state_t::is_partition_stats_enabled)
.def("couple_state",
&state_t::couple_state)
.def("decouple_state",
&state_t::decouple_state)
.def("clear_egroups",
&state_t::clear_egroups)
.def("rebuild_neighbour_sampler",
&state_t::rebuild_neighbour_sampler)
.def("sync_emat",
&state_t::sync_emat);
});
export_sbm_state();
class_<vcmap_t>("unity_vprop_t").def("_get_any", &get_any<vcmap_t>);
class_<ecmap_t>("unity_eprop_t").def("_get_any", &get_any<ecmap_t>);
......
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2017 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graph_tool.hh"
#include "random.hh"
#include <boost/python.hpp>
#include "graph_blockmodel_util.hh"
#include "graph_blockmodel.hh"
#include "graph_state.hh"
using namespace boost;
using namespace graph_tool;
GEN_DISPATCH(block_state, BlockState, BLOCK_STATE_params)
using namespace boost::python;
void export_sbm_state()
{
block_state::dispatch
([&](auto* s)
{
typedef typename std::remove_reference<decltype(*s)>::type state_t;
void (state_t::*remove_vertex)(size_t) =
&state_t::remove_vertex;
void (state_t::*add_vertex)(size_t, size_t) =
&state_t::add_vertex;
void (state_t::*move_vertex)(size_t, size_t) =
&state_t::move_vertex;
void (state_t::*remove_vertices)(python::object) =
&state_t::remove_vertices;
void (state_t::*add_vertices)(python::object, python::object) =
&state_t::add_vertices;
void (state_t::*move_vertices)(python::object, python::object) =
&state_t::move_vertices;
double (state_t::*virtual_move)(size_t, size_t, size_t,
entropy_args_t) =
&state_t::virtual_move;
size_t (state_t::*sample_block)(size_t, double, rng_t&) =
&state_t::sample_block;
size_t (state_t::*random_neighbour)(size_t, rng_t&) =
&state_t::random_neighbour;
double (state_t::*get_move_prob)(size_t, size_t, size_t, double,
bool) =
&state_t::get_move_prob;
void (state_t::*merge_vertices)(size_t, size_t) =
&state_t::merge_vertices;
void (state_t::*set_partition)(boost::any&) =
&state_t::set_partition;
class_<state_t> c(name_demangle(typeid(state_t).name()).c_str(),
no_init);
c.def("remove_vertex", remove_vertex)
.def("add_vertex", add_vertex)
.def("remove_vertices", remove_vertices)
.def("add_vertices", add_vertices)
.def("move_vertex", move_vertex)
.def("move_vertices", move_vertices)
.def("set_partition", set_partition)
.def("virtual_move", virtual_move)
.def("merge_vertices", merge_vertices)
.def("sample_block", sample_block)
.def("sample_neighbour", random_neighbour)
.def("entropy", &state_t::entropy)
.def("get_partition_dl", &state_t::get_partition_dl)
.def("get_deg_dl", &state_t::get_deg_dl)
.def("get_move_prob", get_move_prob)
.def("enable_partition_stats",
&state_t::enable_partition_stats)
.def("disable_partition_stats",
&state_t::disable_partition_stats)
.def("is_partition_stats_enabled",
&state_t::is_partition_stats_enabled)
.def("couple_state",
&state_t::couple_state)
.def("decouple_state",
&state_t::decouple_state)
.def("clear_egroups",
&state_t::clear_egroups)
.def("rebuild_neighbour_sampler",
&state_t::rebuild_neighbour_sampler)
.def("sync_emat",
&state_t::sync_emat);
});
}
......@@ -435,63 +435,13 @@ ldegs_map_t ldegs_map_copy(ldegs_map_t& ldegs)
return ldegs;
}
void export_lsbm();
void export_layered_blockmodel_state()
{
using namespace boost::python;
block_state::dispatch
([&](auto* bs)
{
typedef typename std::remove_reference<decltype(*bs)>::type block_state_t;
layered_block_state<block_state_t>::dispatch
([&](auto* s)
{
typedef typename std::remove_reference<decltype(*s)>::type state_t;
double (state_t::*virtual_move)(size_t, size_t, size_t, entropy_args_t) =
&state_t::virtual_move;
size_t (state_t::*sample_block)(size_t, double, rng_t&)
= &state_t::sample_block;
double (state_t::*get_move_prob)(size_t, size_t, size_t, double,
bool)
= &state_t::get_move_prob;
void (state_t::*merge_vertices)(size_t, size_t)
= &state_t::merge_vertices;
void (state_t::*set_partition)(boost::any&)
= &state_t::set_partition;
void (state_t::*move_vertices)(python::object, python::object) =
&state_t::move_vertices;
void (state_t::*remove_vertices)(python::object) =
&state_t::remove_vertices;
void (state_t::*add_vertices)(python::object, python::object) =
&state_t::add_vertices;
class_<state_t> c(name_demangle(typeid(state_t).name()).c_str(),
no_init);
c.def("remove_vertex", &state_t::remove_vertex)
.def("add_vertex", &state_t::add_vertex)
.def("move_vertex", &state_t::move_vertex)
.def("add_vertices", add_vertices)
.def("remove_vertices", remove_vertices)
.def("move_vertices", move_vertices)
.def("set_partition", set_partition)
.def("virtual_move", virtual_move)
.def("merge_vertices", merge_vertices)
.def("sample_block", sample_block)
.def("entropy", &state_t::entropy)
.def("get_partition_dl", &state_t::get_partition_dl)
.def("get_deg_dl", &state_t::get_deg_dl)
.def("get_move_prob", get_move_prob)
.def("enable_partition_stats",
&state_t::enable_partition_stats)
.def("disable_partition_stats",
&state_t::disable_partition_stats)
.def("is_partition_stats_enabled",
&state_t::is_partition_stats_enabled);
});
});
export_lsbm();
def("make_layered_block_state", &make_layered_block_state);
def("split_layers", &split_layers);
......
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2017 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#define BOOST_PYTHON_MAX_ARITY 40
#include <boost/python.hpp>
#include "graph_tool.hh"
#include "random.hh"
#include "graph_blockmodel_util.hh"
#include "graph_blockmodel.hh"
#include "graph_blockmodel_layers_util.hh"
#define BASE_STATE_params BLOCK_STATE_params
#include "graph_blockmodel_layers.hh"
#include "graph_state.hh"
using namespace boost;
using namespace graph_tool;
GEN_DISPATCH(block_state, BlockState, BLOCK_STATE_params)
template <class BaseState>
GEN_DISPATCH(layered_block_state, Layers<BaseState>::template LayeredBlockState,
LAYERED_BLOCK_STATE_params)
void export_lsbm()
{
using namespace boost::python;
block_state::dispatch
([&](auto* bs)
{
typedef typename std::remove_reference<decltype(*bs)>::type block_state_t;
layered_block_state<block_state_t>::dispatch
([&](auto* s)
{
typedef typename std::remove_reference<decltype(*s)>::type state_t;
double (state_t::*virtual_move)(size_t, size_t, size_t, entropy_args_t) =
&state_t::virtual_move;
size_t (state_t::*sample_block)(size_t, double, rng_t&)
= &state_t::sample_block;
double (state_t::*get_move_prob)(size_t, size_t, size_t, double,
bool)
= &state_t::get_move_prob;
void (state_t::*merge_vertices)(size_t, size_t)
= &state_t::merge_vertices;
void (state_t::*set_partition)(boost::any&)
= &state_t::set_partition;
void (state_t::*move_vertices)(python::object, python::object) =
&state_t::move_vertices;
void (state_t::*remove_vertices)(python::object) =
&state_t::remove_vertices;
void (state_t::*add_vertices)(python::object, python::object) =
&state_t::add_vertices;
class_<state_t> c(name_demangle(typeid(state_t).name()).c_str(),
no_init);
c.def("remove_vertex", &state_t::remove_vertex)
.def("add_vertex", &state_t::add_vertex)
.def("move_vertex", &state_t::move_vertex)
.def("add_vertices", add_vertices)
.def("remove_vertices", remove_vertices)
.def("move_vertices", move_vertices)
.def("set_partition", set_partition)
.def("virtual_move", virtual_move)
.def("merge_vertices", merge_vertices)
.def("sample_block", sample_block)
.def("entropy", &state_t::entropy)
.def("get_partition_dl", &state_t::get_partition_dl)
.def("get_deg_dl", &state_t::get_deg_dl)
.def("get_move_prob", get_move_prob)
.def("enable_partition_stats",
&state_t::enable_partition_stats)
.def("disable_partition_stats",
&state_t::disable_partition_stats)
.def("is_partition_stats_enabled",
&state_t::is_partition_stats_enabled);
});
});
}
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