From cbc7723617af588eed9b3435320ea4f90e2e8c00 Mon Sep 17 00:00:00 2001 From: Tiago de Paula Peixoto Date: Thu, 27 Jun 2013 18:58:28 +0200 Subject: [PATCH] Fix bug in run_action.inline() This removes old dependency on an outdated graph wrapper which did edge index housekeeping. --- src/graph/Makefile.am | 1 - src/graph/graph_wrap.hh | 367 ------------------ src/graph_tool/run_action/inline.py | 6 +- .../run_action/run_action_support.hh | 1 - 4 files changed, 3 insertions(+), 372 deletions(-) delete mode 100644 src/graph/graph_wrap.hh diff --git a/src/graph/Makefile.am b/src/graph/Makefile.am index 0c6a2a08..cc287120 100644 --- a/src/graph/Makefile.am +++ b/src/graph/Makefile.am @@ -50,7 +50,6 @@ libgraph_tool_core_la_include_HEADERS = \ graph_python_interface.hh \ graph_selectors.hh \ graph_util.hh \ - graph_wrap.hh \ histogram.hh \ mpl_nested_loop.hh \ numpy_bind.hh \ diff --git a/src/graph/graph_wrap.hh b/src/graph/graph_wrap.hh deleted file mode 100644 index 8bdec4a4..00000000 --- a/src/graph/graph_wrap.hh +++ /dev/null @@ -1,367 +0,0 @@ -// graph-tool -- a general graph modification and manipulation thingy -// -// Copyright (C) 2006-2013 Tiago de Paula Peixoto -// -// 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 . - -#ifndef GRAPH_WRAP_HH -#define GRAPH_WRAP_HH - -#include -#include "graph_util.hh" -#include "graph_selectors.hh" - -#include - -#include "tr1_include.hh" -#include TR1_HEADER(unordered_map) - - -// Graph wrapper which takes care of edge index housekeeping - -namespace boost -{ -using namespace graph_tool; - -struct graph_wrap_tag {}; - -template -class GraphWrap -{ - public: - GraphWrap(Graph& g, GraphInterface& gi) - : _g(g), _gi(gi) {} - - typedef typename vertex_property_type::type vertex_property_type; - typedef typename edge_property_type::type edge_property_type; - typedef typename Graph::graph_tag orig_wrap_tag; - typedef graph_wrap_tag graph_tag; - typedef Graph orig_graph_t; - - typedef typename graph_traits::vertex_descriptor vertex_descriptor; - typedef typename graph_traits::edge_descriptor edge_descriptor; - - Graph& _g; - GraphInterface& _gi; -}; - -namespace detail { - - template - struct graph_wrap_edge_property_map { - private: - PM underlying_pm; - - public: - typedef typename property_traits::key_type key_type; - typedef typename property_traits::value_type value_type; - typedef typename property_traits::reference reference; - typedef typename property_traits::category category; - - explicit graph_wrap_edge_property_map(const PM& pm): underlying_pm(pm) {} - - friend reference - get(const graph_wrap_edge_property_map& m, - const key_type& e) { - return get(m.underlying_pm, e.underlying_desc); - } - - friend void - put(const graph_wrap_edge_property_map& m, - const key_type& e, - const value_type& v) { - put(m.underlying_pm, e, v); - } - - reference operator[](const key_type& k) { - return (this->underlying_pm)[k]; - } - }; - - struct graph_wrap_vertex_property_selector { - template - struct bind_ { - typedef typename ReverseGraph::orig_graph_t Graph; - typedef property_map PMap; - typedef typename PMap::type type; - typedef typename PMap::const_type const_type; - }; - }; - - struct graph_wrap_edge_property_selector { - template - struct bind_ { - typedef typename ReverseGraph::orig_graph_t Graph; - typedef property_map PMap; - typedef graph_wrap_edge_property_map type; - typedef graph_wrap_edge_property_map const_type; - }; - }; - -} // namespace detail - -template <> -struct vertex_property_selector { - typedef detail::graph_wrap_vertex_property_selector type; -}; - -template <> -struct edge_property_selector { - typedef detail::graph_wrap_edge_property_selector type; -}; - - -template -GraphWrap graph_wrap(Graph& g, GraphInterface& gi) -{ - return GraphWrap(g, gi); -} - -template -struct graph_traits >: public graph_traits {}; - -template -struct graph_traits >: - public graph_traits {}; - -template -struct property_map, Tag>: - public property_map {}; - -template -typename property_map::type -get(Tag t, const GraphWrap& g) -{ - return get(t, g._g); -} - -template -inline typename graph_traits >::vertex_descriptor -source(typename graph_traits >::edge_descriptor e, - const GraphWrap& g) -{ - return source(e, g._g); -} - -template -inline typename graph_traits >::vertex_descriptor -target(typename graph_traits >::edge_descriptor e, - const GraphWrap& g) -{ - return target(e, g._g); -} - -template -inline typename graph_traits >::vertex_descriptor -vertex(typename graph_traits >::vertices_size_type n, - const GraphWrap& g) -{ - return vertex(n, g._g); -} - -template -inline std::pair >::vertex_iterator, - typename graph_traits >::vertex_iterator> -vertices(const GraphWrap& g) -{ - return vertices(g._g); -} - -template -inline std::pair >::edge_iterator, - typename graph_traits >::edge_iterator> -edges(const GraphWrap& g) -{ - return edges(g._g); -} - -template -inline std::pair >::out_edge_iterator, - typename graph_traits >::out_edge_iterator > -out_edges(typename graph_traits >::vertex_descriptor u, - const GraphWrap& g) -{ - return out_edges(u, g._g); -} - -template -inline std::pair >::in_edge_iterator, - typename graph_traits >::in_edge_iterator > -in_edges(typename graph_traits >::vertex_descriptor u, - const GraphWrap& g) -{ - return in_edges(u, g._g); -} - -template -inline -std::pair >::adjacency_iterator, - typename graph_traits >::adjacency_iterator> -adjacent_vertices - (typename graph_traits >::vertex_descriptor u, - const GraphWrap& g) -{ - return adjacent_vertices(u, g._g); -} - -template -inline typename graph_traits >::vertices_size_type -num_vertices(const GraphWrap& g) -{ - return num_vertices(g._g); -} - -template -inline typename graph_traits >::edges_size_type -num_edges(const GraphWrap& g) -{ - return g._gi.GetNumberOfEdges(); -} - -template -inline typename graph_traits >::degree_size_type -out_degree(typename graph_traits >::vertex_descriptor u, - const GraphWrap& g) -{ - return out_degree(u, g._g); -} - -template -inline typename graph_traits >::degree_size_type -in_degree(typename graph_traits >::vertex_descriptor u, - const GraphWrap& g) -{ - return in_degree(u, g._g); -} - -template -inline typename graph_traits >::degree_size_type -degree(typename graph_traits >::vertex_descriptor u, - const GraphWrap& g) -{ - return degree(u, g._g); -} - -template -inline std::pair >::edge_descriptor, - bool> -add_edge(typename graph_traits >::vertex_descriptor u, - typename graph_traits >::vertex_descriptor v, - GraphWrap g) -{ - std::pair >::edge_descriptor, bool> - retval = add_edge(u, v, g._g); - g._gi.AddEdgeIndex(retval.first); - return retval; -} - -template -inline void remove_edge -(typename graph_traits >::edge_descriptor e, - GraphWrap g) -{ - g._gi.RemoveEdgeIndex(e); -} - -template -inline void remove_edge(typename graph_traits >::vertex_descriptor u, - typename graph_traits >::vertex_descriptor v, - GraphWrap g) -{ - vector >::edge_descriptor> - removed_edges; - - typename graph_traits >::out_edge_iterator e, e_end; - for(tie(e, e_end) = out_edges(u, g); e != e_end; ++e) - if (target(*e, g) == v) - removed_edges.push_back(*e); - for (typeof(removed_edges.begin()) iter = removed_edges.begin(); - iter != removed_edges.end(); ++iter) - remove_edge(*iter, g); -} - - -template -inline typename graph_traits >::vertex_descriptor -add_vertex(GraphWrap g) -{ - return add_vertex(g._g); -} - -template -inline void clear_vertex(typename graph_traits >::vertex_descriptor u, - GraphWrap g) -{ - typedef GraphWrap graph_t; - GraphInterface::edge_index_map_t edge_index = g._gi.GetEdgeIndex(); - - tr1::unordered_map::edge_descriptor> del_es; - typename graph_traits::out_edge_iterator e, e_end; - for (tie(e,e_end) = out_edges(u, g); e != e_end; ++e) - del_es[edge_index[*e]] = *e; - - typename in_edge_iteratorS::type ie, ie_end; - for (tie(ie,ie_end) = in_edge_iteratorS::get_edges(u, g); - ie != ie_end; ++ie) - del_es[edge_index[*ie]] = *ie; - - for (typeof(del_es.begin()) iter = del_es.begin(); iter != del_es.end(); - ++iter) - remove_edge(iter->second, g); -} - -// filtered graphs lack a remove_vertex function... -template -inline void remove_vertex(Vertex u, const filtered_graph& g) -{ - remove_vertex(u, const_cast(g.m_g)); -} - -// reverse graphs lack a remove_vertex function... -template -inline void remove_vertex(Vertex u, const reverse_graph& g) -{ - remove_vertex(u, const_cast(g.m_g)); -} - -template -inline void remove_vertex(typename graph_traits >::vertex_descriptor u, - GraphWrap g) -{ - clear_vertex(u, g); - typedef typename graph_traits::vertex_descriptor vertex_t; - remove_vertex(vertex_t(u), g._g); -} - - -template -inline void -remove_out_edge_if(typename graph_traits >::vertex_descriptor u, - Predicate predicate, GraphWrap g) -{ - vector >::edge_descriptor> - removed_edges; - - typename graph_traits >::out_edge_iterator e, e_end; - for(tie(e, e_end) = out_edges(u, g); e != e_end; ++e) - if (predicate(*e)) - removed_edges.push_back(*e); - for (typeof(removed_edges.begin()) iter = removed_edges.begin(); - iter != removed_edges.end(); ++iter) - remove_edge(*iter, g); -} - -} - -#endif // GRAPH_WRAP_HH diff --git a/src/graph_tool/run_action/inline.py b/src/graph_tool/run_action/inline.py index 376a8f02..daf6752f 100644 --- a/src/graph_tool/run_action/inline.py +++ b/src/graph_tool/run_action/inline.py @@ -175,11 +175,11 @@ def inline(code, arg_names=None, local_dict=None, gi = "__gt__" + arg + "__gi" graph_type = get_graph_type(arg_val) gi_val = arg_val._Graph__graph - arg_def += "typedef GraphWrap<%s > %s_graph_t;\n" % (graph_type, arg) + arg_def += "typedef %s %s_graph_t;\n" % (graph_type, arg) arg_def += "GraphInterface& %s = python::extract(%s);\n" % \ (gi, alias) - arg_def += "%s_graph_t %s = graph_wrap(*boost::any_cast<%s*>(%s.GetGraphView()), %s);\n" % \ - (arg, arg, graph_type, gi, gi) + arg_def += "%s_graph_t& %s = *boost::any_cast<%s*>(%s.GetGraphView());\n" % \ + (arg, arg, graph_type, gi) arg_alias.append(alias) alias_dict[alias] = gi_val elif type(arg_val) == PropertyMap: diff --git a/src/graph_tool/run_action/run_action_support.hh b/src/graph_tool/run_action/run_action_support.hh index b09c4665..8840f8b2 100644 --- a/src/graph_tool/run_action/run_action_support.hh +++ b/src/graph_tool/run_action/run_action_support.hh @@ -20,7 +20,6 @@ #include #include #include "graph.hh" -#include "graph_wrap.hh" #include "graph_filtering.hh" #include "graph_properties.hh" #include "histogram.hh" -- GitLab