Commit 4c3b87a8 authored by Jeff Trull's avatar Jeff Trull
Browse files

Mass conversion of bind() calls to lambdas

Source file work done with custom-modified versions of clang-format
and clang-tidy, via the modernize-avoid-bind checker. Headers were
modified by hand. A script removed uses of <functional> and <boost/bind.hpp>.
parent 1f792136
......@@ -144,27 +144,31 @@ void betweenness(GraphInterface& g, std::vector<size_t>& pivots,
if (!weight.empty())
{
run_action<>()
(g, std::bind<>(get_weighted_betweenness(),
std::placeholders::_1,
std::ref(pivots),
g.get_vertex_index(),
std::placeholders::_2,
std::placeholders::_3, weight,
g.get_edge_index_range()),
edge_floating_properties(),
vertex_floating_properties())
(edge_betweenness, vertex_betweenness);
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_weighted_betweenness()
(std::forward<decltype(graph)>(graph), pivots,
g.get_vertex_index(), std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), weight,
g.get_edge_index_range());
},
edge_floating_properties(), vertex_floating_properties())(
edge_betweenness, vertex_betweenness);
}
else
{
run_action<>()
(g, std::bind<void>(get_betweenness(), std::placeholders::_1,
std::ref(pivots),
g.get_vertex_index(), std::placeholders::_2,
std::placeholders::_3),
edge_floating_properties(),
vertex_floating_properties())
(edge_betweenness, vertex_betweenness);
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_betweenness()
(std::forward<decltype(graph)>(graph), pivots,
g.get_vertex_index(), std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3));
},
edge_floating_properties(), vertex_floating_properties())(
edge_betweenness, vertex_betweenness);
}
}
......@@ -207,9 +211,14 @@ double central_point(GraphInterface& g,
{
double c = 0.0;
run_action<graph_tool::detail::never_reversed>()
(g, std::bind<>(get_central_point_dominance(), std::placeholders::_1,
std::placeholders::_2, std::ref(c)),
vertex_scalar_properties()) (vertex_betweenness);
(g,
[&](auto&& graph, auto&& a2)
{
return get_central_point_dominance()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2), c);
},
vertex_scalar_properties())(vertex_betweenness);
return c;
}
......
......@@ -22,7 +22,6 @@
#include "graph_closeness.hh"
#include <functional>
#include <boost/python.hpp>
using namespace std;
......@@ -33,20 +32,30 @@ void do_get_closeness(GraphInterface& gi, boost::any weight,
{
if (weight.empty())
{
run_action<>()(gi,
std::bind(get_closeness(), std::placeholders::_1,
gi.get_vertex_index(), no_weightS(),
std::placeholders::_2, harmonic, norm),
writable_vertex_scalar_properties())(closeness);
run_action<>()
(gi,
[&](auto&& graph, auto&& a2)
{
return get_closeness()
(std::forward<decltype(graph)>(graph),
gi.get_vertex_index(), no_weightS(),
std::forward<decltype(a2)>(a2), harmonic, norm);
},
writable_vertex_scalar_properties())(closeness);
}
else
{
run_action<>()(gi,
std::bind(get_closeness(), std::placeholders::_1,
gi.get_vertex_index(), std::placeholders::_2,
std::placeholders::_3, harmonic, norm),
edge_scalar_properties(),
writable_vertex_scalar_properties())(weight, closeness);
run_action<>()
(gi,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_closeness()
(std::forward<decltype(graph)>(graph),
gi.get_vertex_index(), std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), harmonic, norm);
},
edge_scalar_properties(),
writable_vertex_scalar_properties())(weight, closeness);
}
}
......
......@@ -37,11 +37,15 @@ size_t eigentrust(GraphInterface& g, boost::any c, boost::any t,
size_t iter = 0;
run_action<>()
(g, bind(get_eigentrust(),
_1, g.get_vertex_index(), g.get_edge_index(), _2,
_3, epslon, max_iter, ref(iter)),
writable_edge_scalar_properties(),
vertex_floating_properties())(c,t);
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_eigentrust()
(std::forward<decltype(graph)>(graph), g.get_vertex_index(),
g.get_edge_index(), std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), epslon, max_iter, iter);
},
writable_edge_scalar_properties(), vertex_floating_properties())(c, t);
return iter;
}
......
......@@ -42,11 +42,15 @@ long double eigenvector(GraphInterface& g, boost::any w, boost::any c,
long double eig = 0;
run_action<>()
(g, std::bind(get_eigenvector(), std::placeholders::_1, g.get_vertex_index(),
std::placeholders::_2, std::placeholders::_3, epsilon, max_iter,
std::ref(eig)),
weight_props_t(),
vertex_floating_properties())(w, c);
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_eigenvector()
(std::forward<decltype(graph)>(graph), g.get_vertex_index(),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), epsilon, max_iter, eig);
},
weight_props_t(), vertex_floating_properties())(w, c);
return eig;
}
......
......@@ -68,11 +68,15 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y,
long double eig = 0;
run_action<>()
(g, std::bind(get_hits_dispatch(), std::placeholders::_1, g.get_vertex_index(),
std::placeholders::_2, std::placeholders::_3, y, epsilon, max_iter,
std::ref(eig)),
weight_props_t(),
vertex_floating_properties())(w, x);
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_hits_dispatch()
(std::forward<decltype(graph)>(graph), g.get_vertex_index(),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), y, epsilon, max_iter, eig);
},
weight_props_t(), vertex_floating_properties())(w, x);
return eig;
}
......
......@@ -53,12 +53,18 @@ void katz(GraphInterface& g, boost::any w, boost::any c, boost::any beta,
if(beta.empty())
beta = beta_map_t();
run_action<>()(g, std::bind(get_katz(), std::placeholders::_1, g.get_vertex_index(),
std::placeholders::_2, std::placeholders::_3,
std::placeholders::_4, alpha, epsilon, max_iter),
weight_props_t(),
vertex_floating_properties(),
beta_props_t())(w, c, beta);
run_action<>()
(g,
[&](auto&& graph, auto&& a2, auto&& a3, auto&& a4)
{
return get_katz()
(std::forward<decltype(graph)>(graph), g.get_vertex_index(),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3),
std::forward<decltype(a4)>(a4), alpha, epsilon, max_iter);
},
weight_props_t(), vertex_floating_properties(),
beta_props_t())(w, c, beta);
}
void export_katz()
......
......@@ -18,7 +18,6 @@
#include "graph_filtering.hh"
#include <boost/python.hpp>
#include <boost/bind.hpp>
#include "graph.hh"
#include "graph_selectors.hh"
......@@ -56,12 +55,17 @@ size_t pagerank(GraphInterface& g, boost::any rank, boost::any pers,
size_t iter;
run_action<>()
(g, std::bind(get_pagerank(),
std::placeholders::_1, g.get_vertex_index(), std::placeholders::_2,
std::placeholders::_3, std::placeholders::_4, d,
epsilon, max_iter, std::ref(iter)),
vertex_floating_properties(),
pers_props_t(), weight_props_t())(rank, pers, weight);
(g,
[&](auto&& graph, auto&& a2, auto&& a3, auto&& a4)
{
return get_pagerank()
(std::forward<decltype(graph)>(graph), g.get_vertex_index(),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3),
std::forward<decltype(a4)>(a4), d, epsilon, max_iter, iter);
},
vertex_floating_properties(), pers_props_t(),
weight_props_t())(rank, pers, weight);
return iter;
}
......
......@@ -36,11 +36,16 @@ void trust_transitivity(GraphInterface& g, int64_t source, int64_t target,
if (!belongs<vertex_floating_vector_properties>()(t))
throw ValueException("vertex property must be of floating point valued vector type");
run_action<>()(g,
bind<void>(get_trust_transitivity(), _1, g.get_vertex_index(),
source, target, _2, _3),
edge_floating_properties(),
vertex_floating_vector_properties())(c,t);
run_action<>()
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_trust_transitivity()
(std::forward<decltype(graph)>(graph), g.get_vertex_index(),
source, target, std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3));
},
edge_floating_properties(), vertex_floating_vector_properties())(c, t);
}
void export_trust_transitivity()
......
......@@ -45,8 +45,13 @@ boost::python::tuple global_clustering(GraphInterface& g, boost::any weight)
double c, c_err;
run_action<graph_tool::detail::never_directed>()
(g, std::bind(get_global_clustering(), std::placeholders::_1,
std::placeholders::_2, std::ref(c), std::ref(c_err)),
(g,
[&](auto&& graph, auto&& a2)
{
return get_global_clustering()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2), c, c_err);
},
weight_props_t())(weight);
return boost::python::make_tuple(c, c_err);
}
......@@ -64,12 +69,15 @@ void local_clustering(GraphInterface& g, boost::any prop, boost::any weight)
weight = weight_map_t();
run_action<>()
(g, std::bind(set_clustering_to_property(),
std::placeholders::_1,
std::placeholders::_2,
std::placeholders::_3),
weight_props_t(),
writable_vertex_scalar_properties())(weight, prop);
(g,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return set_clustering_to_property()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3));
},
weight_props_t(), writable_vertex_scalar_properties())(weight, prop);
}
using namespace boost::python;
......
......@@ -35,9 +35,13 @@ struct prop_vector
boost::any operator()(const vector<boost::any>& props, size_t size) const
{
boost::any prop_vec;
boost::mpl::for_each<PropertySequence>
(std::bind(get_prop_vector(), std::placeholders::_1, std::ref(props),
std::ref(prop_vec), size));
boost::mpl::for_each<PropertySequence>(
[&](auto&& graph)
{
return get_prop_vector()
(std::forward<decltype(graph)>(graph), props, prop_vec,
size);
});
return prop_vec;
}
......@@ -92,8 +96,14 @@ void extended_clustering(GraphInterface& g, boost::python::list props)
properties_vector;
run_action<>()
(g, std::bind<void>(get_extended_clustering(), std::placeholders::_1,
any_cast<GraphInterface::vertex_index_map_t>(g.get_vertex_index()),
std::placeholders::_2),
properties_vector()) (vprop);
(g,
[&](auto&& graph, auto&& a2)
{
return get_extended_clustering()
(std::forward<decltype(graph)>(graph),
any_cast<GraphInterface::vertex_index_map_t>(
g.get_vertex_index()),
std::forward<decltype(a2)>(a2));
},
properties_vector())(vprop);
}
......@@ -65,9 +65,13 @@ void get_motifs(GraphInterface& g, size_t k, boost::python::list subgraph_list,
{
GraphInterface& sub =
boost::python::extract<GraphInterface&>(subgraph_list[i]);
run_action<>()(sub, std::bind(append_to_list(),
std::placeholders::_1,
std::ref(list)))();
run_action<>()
(sub,
[&](auto&& graph)
{
return append_to_list()
(std::forward<decltype(graph)>(graph), list);
})();
}
std::vector<size_t> phist;
......@@ -91,11 +95,15 @@ void get_motifs(GraphInterface& g, size_t k, boost::python::list subgraph_list,
std::vector<std::vector<vmap_t> > vmaps;
run_action<>()
(g, std::bind(get_all_motifs(collect_vmaps, plist[0], comp_iso,
fill_list, rng),
std::placeholders::_1, k, std::ref(list), std::ref(phist),
std::ref(vmaps), std::placeholders::_2),
boost::mpl::vector<sample_all,sample_some>())(sampler);
(g,
[&](auto&& graph, auto&& a2)
{
return get_all_motifs(collect_vmaps, plist[0], comp_iso, fill_list,
rng)(std::forward<decltype(graph)>(graph), k,
list, phist, vmaps,
std::forward<decltype(a2)>(a2));
},
boost::mpl::vector<sample_all, sample_some>())(sampler);
for (size_t i = 0; i < phist.size(); ++i)
hist.append(phist[i]);
......@@ -125,8 +133,12 @@ void get_motifs(GraphInterface& g, size_t k, boost::python::list subgraph_list,
boost::mpl::bool_<false>, boost::mpl::bool_<true>,
boost::mpl::bool_<true> >::type gviews;
run_action<gviews>()
(sub, std::bind(retrieve_from_list(), std::placeholders::_1,
std::ref(list), std::ref(done)))();
(sub,
[&](auto&& graph)
{
return retrieve_from_list()
(std::forward<decltype(graph)>(graph), list, done);
})();
if (!done)
subgraph_list.append(sub);
}
......
......@@ -150,7 +150,8 @@ struct sample_some
void operator()(std::vector<val_type>& extend, size_t d)
{
typedef std::uniform_real_distribution<double> rdist_t;
auto random = std::bind(rdist_t(), std::ref(*_rng));
auto random = [this] { return rdist_t()(*_rng); };
double pd = (*_p)[d+1];
size_t nc = extend.size();
......@@ -177,8 +178,7 @@ struct sample_some
typedef std::uniform_int_distribution<size_t> idist_t;
for (size_t i = 0; i < n; ++i)
{
auto random_v = std::bind(idist_t(0, extend.size()-i-1),
std::ref(*_rng));
auto random_v = [this, &extend, i] { return idist_t(0, extend.size()-i-1)(*_rng); };
size_t j;
#pragma omp critical (random)
{
......@@ -331,8 +331,7 @@ struct get_all_motifs
hist.resize(subgraph_list.size());
typedef std::uniform_real_distribution<double> rdist_t;
auto random = std::bind(rdist_t(), std::ref(rng));
auto random = [this] { return rdist_t()(rng); };
// the set of vertices V to be sampled (filled only if p < 1)
std::vector<size_t> V;
if (p < 1)
......@@ -349,8 +348,7 @@ struct get_all_motifs
typedef std::uniform_int_distribution<size_t> idist_t;
for (size_t i = 0; i < n; ++i)
{
auto random_v = std::bind(idist_t(0, V.size()-i-1),
std::ref(rng));
auto random_v = [&V, i, this] { return idist_t(0, V.size()-i-1)(rng); };
size_t j = i + random_v();
std::swap(V[i], V[j]);
}
......
......@@ -94,12 +94,16 @@ assortativity_coefficient(GraphInterface& gi, GraphInterface::deg_t deg,
weight = weight_map_t();
double a = 0, a_err = 0;
run_action<>()(gi,std::bind(get_assortativity_coefficient(),
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3,
std::ref(a), std::ref(a_err)),
all_selectors(), weight_props_t())
(degree_selector(deg), weight);
run_action<>()
(gi,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_assortativity_coefficient()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), a, a_err);
},
all_selectors(), weight_props_t())(degree_selector(deg), weight);
return make_pair(a, a_err);
}
......@@ -118,12 +122,16 @@ scalar_assortativity_coefficient(GraphInterface& gi, GraphInterface::deg_t deg,
weight = weight_map_t();
double a = 0, a_err = 0;
run_action<>()(gi, std::bind(get_scalar_assortativity_coefficient(),
std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3,
std::ref(a), std::ref(a_err)),
scalar_selectors(), weight_props_t())
(degree_selector(deg), weight);
run_action<>()
(gi,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return get_scalar_assortativity_coefficient()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), a, a_err);
},
scalar_selectors(), weight_props_t())(degree_selector(deg), weight);
return make_pair(a, a_err);
}
......
......@@ -1852,9 +1852,13 @@ boost::python::object cairo_draw(GraphInterface& gi,
populate_defaults(ovdefaults, vdefaults);
run_action<>()
(gi, std::bind(populate_edge_attrs(), std::placeholders::_1,
oeattrs, std::ref(eattrs), oedefaults,
std::ref(edefaults)))();
(gi,
[&](auto&& graph)
{
return populate_edge_attrs()
(std::forward<decltype(graph)>(graph), oeattrs, eattrs,
oedefaults, edefaults);
})();
typedef boost::mpl::push_back<vertex_scalar_properties, no_order>::type
vorder_t;
......@@ -1877,31 +1881,45 @@ boost::python::object cairo_draw(GraphInterface& gi,
if (nodesfirst)
run_action<>()
(gi, std::bind(do_cairo_draw_vertices(), std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::ref(vattrs), std::ref(eattrs), std::ref(vdefaults),
std::ref(edefaults), mtime, dt, std::ref(count),
std::ref(cr), std::ref(yield)),
(gi,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return do_cairo_draw_vertices()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), vattrs, eattrs,
vdefaults, edefaults, mtime, dt, count, cr,
yield);
},
vertex_scalar_vector_properties(),
vorder_t())(pos, vorder);
run_action<>()
(gi, std::bind(do_cairo_draw_edges(), std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::ref(vattrs), std::ref(eattrs),
std::ref(vdefaults), std::ref(edefaults), res,
mtime, dt, std::ref(count), std::ref(cr), std::ref(yield)),
vertex_scalar_vector_properties(),
eorder_t())(pos, eorder);
(gi,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return do_cairo_draw_edges()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), vattrs, eattrs,
vdefaults, edefaults, res, mtime, dt, count, cr,
yield);
},
vertex_scalar_vector_properties(), eorder_t())(pos, eorder);
if (!nodesfirst)
{
run_action<>()
(gi, std::bind(do_cairo_draw_vertices(), std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3,
std::ref(vattrs), std::ref(eattrs), std::ref(vdefaults),
std::ref(edefaults), mtime, dt, std::ref(count),
std::ref(cr), std::ref(yield)),
(gi,
[&](auto&& graph, auto&& a2, auto&& a3)
{
return do_cairo_draw_vertices()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2),
std::forward<decltype(a3)>(a3), vattrs, eattrs,
vdefaults, edefaults, mtime, dt, count, cr,
yield);
},
vertex_scalar_vector_properties(),
vorder_t())(pos, vorder);
}
......@@ -1935,8 +1953,13 @@ void apply_transforms(GraphInterface& gi, boost::any pos, double xx, double yx,
{
Cairo::Matrix m(xx, yx, xy, yy, x0, y0);
run_action<>()
(gi, std::bind(do_apply_transforms(), std::placeholders::_1,
std::placeholders::_2, std::ref(m)),
(gi,
[&](auto&& graph, auto&& a2)
{
return do_apply_transforms()
(std::forward<decltype(graph)>(graph),
std::forward<decltype(a2)>(a2), m);
},
vertex_scalar_vector_properties())(pos);