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