Commit 872d1c5d authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix bug when copying graph with filtering disabled

Also, get rid of g.underlying_graph(), and rely on "private" variable
g._Graph__graph instead.
parent 36982c7a
...@@ -284,6 +284,8 @@ BOOST_PYTHON_MODULE(libgraph_tool_core) ...@@ -284,6 +284,8 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
def("get_property_types", &get_property_types); def("get_property_types", &get_property_types);
class_<boost::any>("any"); class_<boost::any>("any");
def("graph_filtering_enabled", &graph_filtering_enabled);
mpl::for_each<mpl::push_back<scalar_types,string>::type>(export_vector_types()); mpl::for_each<mpl::push_back<scalar_types,string>::type>(export_vector_types());
class_<GraphInterface>("GraphInterface", init<>()) class_<GraphInterface>("GraphInterface", init<>())
......
...@@ -91,12 +91,12 @@ GraphInterface::GraphInterface(const GraphInterface& gi) ...@@ -91,12 +91,12 @@ GraphInterface::GraphInterface(const GraphInterface& gi)
typedef mpl::transform<detail::all_graph_views, typedef mpl::transform<detail::all_graph_views,
mpl::quote1<add_pointer> >::type all_graph_views; mpl::quote1<add_pointer> >::type all_graph_views;
run_action<graph_views>()(*this, bind<void>(graph_copy(), _1, _2, run_action<>()(*this, bind<void>(graph_copy(), _1, _2,
_vertex_index, _vertex_index,
gi._vertex_index, gi._vertex_index,
_edge_index, _edge_index,
gi._edge_index), gi._edge_index),
all_graph_views())(gi.GetGraphView()); all_graph_views())(gi.GetGraphView());
} }
// //
......
...@@ -22,6 +22,15 @@ using namespace graph_tool; ...@@ -22,6 +22,15 @@ using namespace graph_tool;
using namespace graph_tool::detail; using namespace graph_tool::detail;
using namespace boost; using namespace boost;
bool graph_tool::graph_filtering_enabled()
{
#ifndef NO_GRAPH_FILTERING
return true;
#else
return false;
#endif
}
// Whenever no implementation is called, the following exception is thrown // Whenever no implementation is called, the following exception is thrown
graph_tool::ActionNotFound::ActionNotFound(const boost::any& graph_view, graph_tool::ActionNotFound::ActionNotFound(const boost::any& graph_view,
const type_info& action, const type_info& action,
...@@ -40,13 +49,13 @@ const char * graph_tool::ActionNotFound::what () const throw () ...@@ -40,13 +49,13 @@ const char * graph_tool::ActionNotFound::what () const throw ()
"information.\n\n"; "information.\n\n";
error += "Graph view: " + string(gcc_demangle(_graph_view.type().name())) error += "Graph view: " + string(gcc_demangle(_graph_view.type().name()))
+ "\n"; + "\n\n";
error += "Action: " + string(gcc_demangle(_action.name())) + "\n"; error += "Action: " + string(gcc_demangle(_action.name())) + "\n\n";
for (size_t i = 0; i < _args.size(); ++i) for (size_t i = 0; i < _args.size(); ++i)
{ {
error += "Arg " + lexical_cast<string>(i+1) + ": " + error += "Arg " + lexical_cast<string>(i+1) + ": " +
string(gcc_demangle(_args[i]->name())) + "\n"; string(gcc_demangle(_args[i]->name())) + "\n\n";
} }
return error.c_str(); return error.c_str();
} }
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
namespace graph_tool namespace graph_tool
{ {
using namespace boost; using namespace boost;
// Graph filtering // Graph filtering
...@@ -624,6 +625,9 @@ struct run_action ...@@ -624,6 +625,9 @@ struct run_action
} }
}; };
// returns true if graph filtering was enabled at compile time
bool graph_filtering_enabled();
} //graph_tool namespace } //graph_tool namespace
#endif // FILTERING_HH #endif // FILTERING_HH
...@@ -43,12 +43,12 @@ __all__ = ["local_clustering", "global_clustering", "extended_clustering"] ...@@ -43,12 +43,12 @@ __all__ = ["local_clustering", "global_clustering", "extended_clustering"]
def local_clustering(g, prop=None): def local_clustering(g, prop=None):
if prop == None: if prop == None:
prop = g.new_vertex_property("double") prop = g.new_vertex_property("double")
libgraph_tool_clustering.extended_clustering(g.underlying_graph(), libgraph_tool_clustering.extended_clustering(g._Graph__graph,
[_prop("v", g, prop)]) [_prop("v", g, prop)])
return prop return prop
def global_clustering(g): def global_clustering(g):
c = libgraph_tool_clustering.global_clustering(g.underlying_graph()) c = libgraph_tool_clustering.global_clustering(g._Graph__graph)
return c return c
def extended_clustering(g, props=None, max_depth=3): def extended_clustering(g, props=None, max_depth=3):
...@@ -56,6 +56,6 @@ def extended_clustering(g, props=None, max_depth=3): ...@@ -56,6 +56,6 @@ def extended_clustering(g, props=None, max_depth=3):
props = [] props = []
for i in xrange(0, max_depth): for i in xrange(0, max_depth):
props.append(g.new_vertex_property("double")) props.append(g.new_vertex_property("double"))
libgraph_tool_clustering.extended_clustering(g.underlying_graph(), libgraph_tool_clustering.extended_clustering(g._Graph__graph,
[_prop("v", g, p) for p in props]) [_prop("v", g, p) for p in props])
return props return props
...@@ -216,7 +216,8 @@ class Graph(object): ...@@ -216,7 +216,8 @@ class Graph(object):
self.copy_property(v, new_p, g) self.copy_property(v, new_p, g)
self.properties[(v.key_type(),k)] = new_p self.properties[(v.key_type(),k)] = new_p
self.__stashed_filter_state = [g.__filter_state] self.__stashed_filter_state = [g.__filter_state]
self.pop_filter() if libcore.graph_filtering_enabled():
self.pop_filter()
@_handle_exceptions @_handle_exceptions
def copy(self): def copy(self):
...@@ -540,7 +541,7 @@ class Graph(object): ...@@ -540,7 +541,7 @@ class Graph(object):
@_handle_exceptions @_handle_exceptions
def set_vertex_filter(self, property, inverted=False): def set_vertex_filter(self, property, inverted=False):
"""Choose vertex boolean filter property""" """Choose vertex boolean filter property"""
self.__graph.SetVertexFilterProperty(property, inverted) self.__graph.SetVertexFilterProperty(_prop("v", self, property), inverted)
self.__filter_state["vertex_filter"] = (property, inverted) self.__filter_state["vertex_filter"] = (property, inverted)
@_handle_exceptions @_handle_exceptions
...@@ -551,7 +552,7 @@ class Graph(object): ...@@ -551,7 +552,7 @@ class Graph(object):
@_handle_exceptions @_handle_exceptions
def set_edge_filter(self, property, inverted=False): def set_edge_filter(self, property, inverted=False):
"""Choose edge boolean property""" """Choose edge boolean property"""
self.__graph.SetEdgeFilterProperty(property, inverted) self.__graph.SetEdgeFilterProperty(_prop("e", self, property), inverted)
self.__filter_state["edge_filter"] = (property, inverted) self.__filter_state["edge_filter"] = (property, inverted)
@_handle_exceptions @_handle_exceptions
...@@ -607,11 +608,6 @@ class Graph(object): ...@@ -607,11 +608,6 @@ class Graph(object):
"""Get the number of edges""" """Get the number of edges"""
return self.__graph.GetNumberOfEdges() return self.__graph.GetNumberOfEdges()
def underlying_graph(self):
"""Retrieve a GraphInterface from a Graph (for internal use only)"""
return self.__graph
# Pickling support # Pickling support
# ================ # ================
......
...@@ -43,23 +43,23 @@ __all__ = ["assortativity", "scalar_assortativity", ...@@ -43,23 +43,23 @@ __all__ = ["assortativity", "scalar_assortativity",
def assortativity(g, deg): def assortativity(g, deg):
return libgraph_tool_correlations.\ return libgraph_tool_correlations.\
assortativity_coefficient(g.underlying_graph(), _degree(g, deg)) assortativity_coefficient(g._Graph__graph, _degree(g, deg))
def scalar_assortativity(g, deg): def scalar_assortativity(g, deg):
return libgraph_tool_correlations.\ return libgraph_tool_correlations.\
scalar_assortativity_coefficient(g.underlying_graph(), scalar_assortativity_coefficient(g._Graph__graph,
_degree(g, deg)) _degree(g, deg))
def corr_hist(g, deg1, deg2, bins=[[1],[1]], weight=None): def corr_hist(g, deg1, deg2, bins=[[1],[1]], weight=None):
ret = libgraph_tool_correlations.\ ret = libgraph_tool_correlations.\
vertex_correlation_histogram(g.underlying_graph(), _degree(g, deg1), vertex_correlation_histogram(g._Graph__graph, _degree(g, deg1),
_degree(g, deg2), _prop("e", g, weight), _degree(g, deg2), _prop("e", g, weight),
bins[0], bins[1]) bins[0], bins[1])
return [ret[0], [ret[1][0], ret[1][1]]] return [ret[0], [ret[1][0], ret[1][1]]]
def combined_corr_hist(g, deg1, deg2, bins=[[1],[1]]): def combined_corr_hist(g, deg1, deg2, bins=[[1],[1]]):
ret = libgraph_tool_correlations.\ ret = libgraph_tool_correlations.\
vertex_combined_correlation_histogram(g.underlying_graph(), vertex_combined_correlation_histogram(g._Graph__graph,
_degree(g, deg1), _degree(g, deg1),
_degree(g, deg2), _degree(g, deg2),
bins[0], bins[1]) bins[0], bins[1])
......
...@@ -52,7 +52,7 @@ def random_graph(N, deg_sampler, deg_corr=None, directed=True, ...@@ -52,7 +52,7 @@ def random_graph(N, deg_sampler, deg_corr=None, directed=True,
uncorrelated = True uncorrelated = True
else: else:
uncorrelated = False uncorrelated = False
libgraph_tool_generation.gen_random_graph(g.underlying_graph(), N, libgraph_tool_generation.gen_random_graph(g._Graph__graph, N,
deg_sampler, deg_corr, deg_sampler, deg_corr,
uncorrelated, not parallel, uncorrelated, not parallel,
not self_loops, not directed, not self_loops, not directed,
......
...@@ -93,7 +93,7 @@ def inline(g, code, arg_names=[], local_dict=None, ...@@ -93,7 +93,7 @@ def inline(g, code, arg_names=[], local_dict=None,
python::object pg(python::handle<> python::object pg(python::handle<>
(python::borrowed((PyObject*)(self___graph)))); (python::borrowed((PyObject*)(self___graph))));
GraphInterface& g = python::extract<GraphInterface&>(pg); GraphInterface& g = python::extract<GraphInterface&>(pg);
RunAction(g, make_action(boost::make_tuple(${args}), return_val)); RunAction(g, make_action(tr1::make_tuple(${args}), return_val));
// support code hash: ${support_hash} // support code hash: ${support_hash}
""").substitute(args=", ".join(["&%s" %a for a in arg_names]), """).substitute(args=", ".join(["&%s" %a for a in arg_names]),
code_hash=code_hash, support_hash=support_hash) code_hash=code_hash, support_hash=support_hash)
...@@ -105,7 +105,7 @@ def inline(g, code, arg_names=[], local_dict=None, ...@@ -105,7 +105,7 @@ def inline(g, code, arg_names=[], local_dict=None,
local_dict = call_frame.f_locals local_dict = call_frame.f_locals
if global_dict is None: if global_dict is None:
global_dict = call_frame.f_globals global_dict = call_frame.f_globals
local_dict["self___graph"] = g.underlying_graph() # the graph interface local_dict["self___graph"] = g._Graph__graph # the graph interface
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and # RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and
# friends to work properly across DSO boundaries. See # friends to work properly across DSO boundaries. See
......
...@@ -43,31 +43,31 @@ __all__ = ["vertex_hist", "edge_hist", "label_components", ...@@ -43,31 +43,31 @@ __all__ = ["vertex_hist", "edge_hist", "label_components",
def vertex_hist(g, deg, bins=[1]): def vertex_hist(g, deg, bins=[1]):
ret = libgraph_tool_stats.\ ret = libgraph_tool_stats.\
get_vertex_histogram(g.underlying_graph(), _degree(g, deg), bins) get_vertex_histogram(g._Graph__graph, _degree(g, deg), bins)
return [array(ret[0]), ret[1]] return [array(ret[0]), ret[1]]
def edge_hist(g, eprop, bins=[1]): def edge_hist(g, eprop, bins=[1]):
ret = libgraph_tool_stats.\ ret = libgraph_tool_stats.\
get_edge_histogram(g.underlying_graph(), _prop("e", g, eprop), bins) get_edge_histogram(g._Graph__graph, _prop("e", g, eprop), bins)
return [array(ret[0]), ret[1]] return [array(ret[0]), ret[1]]
def label_components(g, vprop=None): def label_components(g, vprop=None):
if vprop == None: if vprop == None:
vprop = g.new_vertex_property("int32_t") vprop = g.new_vertex_property("int32_t")
libgraph_tool_stats.\ libgraph_tool_stats.\
label_components(g.underlying_graph(), _prop("v", g, vprop)) label_components(g._Graph__graph, _prop("v", g, vprop))
return _prop("v", g, vprop) return _prop("v", g, vprop)
def label_parallel_edges(g, eprop): def label_parallel_edges(g, eprop):
if eprop == None: if eprop == None:
eprop = g.new_edge_property("int32_t") eprop = g.new_edge_property("int32_t")
libgraph_tool_stats.\ libgraph_tool_stats.\
label_parallel_edges(g.underlying_graph(), _prop("e", g, eprop)) label_parallel_edges(g._Graph__graph, _prop("e", g, eprop))
return _prop("e", g, eprop) return _prop("e", g, eprop)
def label_self_loops(g, eprop): def label_self_loops(g, eprop):
if eprop == None: if eprop == None:
eprop = g.new_edge_property("int32_t") eprop = g.new_edge_property("int32_t")
libgraph_tool_stats.\ libgraph_tool_stats.\
label_self_loops(g.underlying_graph(), _prop("e", g, eprop)) label_self_loops(g._Graph__graph, _prop("e", g, eprop))
return _prop("e", g, eprop) return _prop("e", g, eprop)
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