Commit 29f9f248 authored by Tiago Peixoto's avatar Tiago Peixoto

Fix copying of filtered graphs

parent 137eb9fd
...@@ -1049,82 +1049,77 @@ class Graph(object): ...@@ -1049,82 +1049,77 @@ class Graph(object):
else: else:
vprune, eprune, rprune = prune vprune, eprune, rprune = prune
if not (vprune or eprune or rprune): if not (vprune or eprune or rprune):
g = GraphView(g) gv = GraphView(g, skip_vfilt=True,
if not vprune: skip_efilt=True)
g.set_vertex_filter(None)
if not eprune:
g.set_edge_filter(None)
if not rprune: if not rprune:
g.set_reversed(False) gv.set_reversed(False)
else:
gv = g
# The filters may or may not not be in the internal property maps
vfilt = g.get_vertex_filter()[0]
efilt = g.get_edge_filter()[0]
# Copy all internal properties from original graph. # Copy all internal properties from original graph.
vprops = [] vprops = []
eprops = [] eprops = []
for k, v in g.vertex_properties.items(): ef_pos = vf_pos = None
vprops.append([_prop("v", g, v), libcore.any()]) for k, m in gv.vertex_properties.items():
for k, v in g.edge_properties.items(): if not vprune and m is vfilt:
eprops.append([_prop("e", g, v), libcore.any()]) vf_pos = len(vprops)
vprops.append([_prop("v", gv, m), libcore.any()])
for k, m in gv.edge_properties.items():
if not eprune and m is efilt:
ef_pos = len(eprops)
eprops.append([_prop("e", gv, m), libcore.any()])
if not vprune and vf_pos is None and vfilt is not None:
vf_pos = len(vprops)
vprops.append([_prop("v", gv, vfilt), libcore.any()])
if not eprune and ef_pos is None and efilt is not None:
ef_pos = len(eprops)
eprops.append([_prop("e", gv, efilt), libcore.any()])
# The vertex ordering # The vertex ordering
if vorder is None: if vorder is None:
vorder = g.new_vertex_property("int") vorder = gv.new_vertex_property("int")
vorder.fa = numpy.arange(g.num_vertices()) vorder.fa = numpy.arange(gv.num_vertices())
# The actual copying of the graph and property maps # The actual copying of the graph and property maps
self.__graph = libcore.GraphInterface(g.__graph, False, vprops, eprops, self.__graph = libcore.GraphInterface(gv.__graph, False,
_prop("v", g, vorder)) vprops,
eprops,
_prop("v", gv, vorder))
# Put the copied properties in the internal dictionary # Put the copied properties in the internal dictionary
for k, v in g.vertex_properties.items(): for i, (k, m) in enumerate(g.vertex_properties.items()):
pmap = new_vertex_property(v.value_type(), pmap = new_vertex_property(m.value_type(),
self.__graph.GetVertexIndex(), self.__graph.GetVertexIndex(),
vprops[0][1]) vprops[i][1])
self.vertex_properties[k] = PropertyMap(pmap, self, "v") self.vertex_properties[k] = PropertyMap(pmap, self, "v")
del vprops[0]
for k, v in g.edge_properties.items(): for i, (k, m) in enumerate(g.edge_properties.items()):
pmap = new_edge_property(v.value_type(), pmap = new_edge_property(m.value_type(),
self.__graph.GetEdgeIndex(), self.__graph.GetEdgeIndex(),
eprops[0][1]) eprops[i][1])
self.edge_properties[k] = PropertyMap(pmap, self, "e") self.edge_properties[k] = PropertyMap(pmap, self, "e")
del eprops[0]
for k, v in g.graph_properties.items(): for k, v in g.graph_properties.items():
new_p = self.new_graph_property(v.value_type()) new_p = self.new_graph_property(v.value_type())
new_p[self] = v[g] new_p[self] = v[g]
self.graph_properties[k] = new_p self.graph_properties[k] = new_p
new_v_filt = None if vf_pos is not None:
if not vprune: pmap = new_vertex_property("bool",
v_filt, v_rev = g.__filter_state["vertex_filter"] self.__graph.GetVertexIndex(),
if v_filt is not None: vprops[vf_pos][1])
if v_filt not in list(g.vertex_properties.values()): pmap = PropertyMap(pmap, self, "v")
new_v_filt = self.new_vertex_property("bool") self.set_vertex_filter(pmap, g.get_vertex_filter()[1])
self.copy_property(v_filt, new_filt) if ef_pos is not None:
pmap = new_edge_property("bool",
else: self.__graph.GetEdgeIndex(),
for k, v in g.vertex_properties.items(): eprops[ef_pos][1])
if v == v_filt: pmap = PropertyMap(pmap, self, "e")
new_v_filt = self.vertex_properties[k] self.set_edge_filter(pmap, g.get_edge_filter()[1])
new_e_filt = None
if not eprune:
e_filt, e_rev = g.__filter_state["edge_filter"]
if e_filt is not None:
if e_filt not in list(g.edge_properties.values()):
new_e_filt = self.new_edge_property("bool")
self.copy_property(e_filt, new_filt)
else:
for k, v in g.edge_properties.items():
if v == e_filt:
new_e_filt = self.edge_properties[k]
if new_v_filt is not None:
self.set_vertex_filter(new_v_filt, v_rev)
if new_e_filt is not None:
self.set_vertex_filter(new_e_filt, e_rev)
if not rprune: if not rprune:
self.set_reversed(g.is_reversed()) self.set_reversed(g.is_reversed())
......
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