Commit 666ccd25 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Improve Graph.copy_property()

The method no longer temporarily alters the vertex or edge filters.
parent e833a522
...@@ -1853,15 +1853,15 @@ class Graph(object): ...@@ -1853,15 +1853,15 @@ class Graph(object):
vs = numpy.asarray((vertex,), dtype="int64") vs = numpy.asarray((vertex,), dtype="int64")
vfilt = self.get_vertex_filter()[0] vfilt = self.get_vertex_filter()[0]
if vfilt is not None: if vfilt is not None:
vfiltptr = vfilt._get_data_ptr() vfiltptr = vfilt.data_ptr()
else: else:
vfiltprt = None vfiltptr = None
for pmap_ in self.__known_properties.values(): for pmap_ in self.__known_properties.values():
pmap = pmap_() pmap = pmap_()
if (pmap is not None and if (pmap is not None and
pmap.key_type() == "v" and pmap.key_type() == "v" and
pmap.is_writable() and pmap.is_writable() and
pmap._get_data_ptr() != vfiltptr): pmap.data_ptr() != vfiltptr):
if fast: if fast:
self.__graph.move_vertex_property(_prop("v", self, pmap), vs) self.__graph.move_vertex_property(_prop("v", self, pmap), vs)
else: else:
...@@ -2216,55 +2216,39 @@ class Graph(object): ...@@ -2216,55 +2216,39 @@ class Graph(object):
if g is None: if g is None:
g = self g = self
sf = self
is_directed = g.is_directed()
efilt = g.get_edge_filter() if full:
vfilt = g.get_vertex_filter() g = GraphView(g, skip_properties=True, skip_efilt=True,
if g is not self: skip_vfilt=True, directed=True)
self_is_directed = self.is_directed() sf = GraphView(sf, skip_properties=True, skip_efilt=True,
self_efilt = self.get_edge_filter() skip_vfilt=True, directed=True)
self_vfilt = self.get_vertex_filter() if src.key_type() == "v":
try: if g.num_vertices() > sf.num_vertices():
if full: raise ValueError("graphs with incompatible sizes (%d, %d)" %
g.set_directed(True) (g.num_vertices(), sf.num_vertices()))
g.clear_filters() try:
if g is not self: sf.__graph.copy_vertex_property(g.__graph,
self.set_directed(True) _prop("v", g, src),
self.clear_filters() _prop("v", sf, tgt))
if src.key_type() == "v": except ValueError:
if g.num_vertices() > self.num_vertices(): raise ValueError("property maps with the following types are"
raise ValueError("graphs with incompatible sizes (%d, %d)" % " not convertible: %s, %s" %
(g.num_vertices(), self.num_vertices())) (src.value_type(), tgt.value_type()))
try: elif src.key_type() == "e":
self.__graph.copy_vertex_property(g.__graph, if g.num_edges() > sf.num_edges():
_prop("v", g, src), raise ValueError("graphs with incompatible sizes (%d, %d)" %
_prop("v", self, tgt)) (g.num_edges(), sf.num_edges()))
except ValueError: try:
raise ValueError("property maps with the following types are" sf.__graph.copy_edge_property(g.__graph,
" not convertible: %s, %s" % _prop("e", g, src),
(src.value_type(), tgt.value_type())) _prop("e", sf, tgt))
elif src.key_type() == "e": except ValueError:
if g.num_edges() > self.num_edges(): raise ValueError("property maps with the following types are"
raise ValueError("graphs with incompatible sizes (%d, %d)" % " not convertible: %s, %s" %
(g.num_edges(), self.num_edges())) (src.value_type(), tgt.value_type()))
try: else:
self.__graph.copy_edge_property(g.__graph, tgt[sf] = src[g]
_prop("e", g, src),
_prop("e", self, tgt))
except ValueError:
raise ValueError("property maps with the following types are"
" not convertible: %s, %s" %
(src.value_type(), tgt.value_type()))
else:
tgt[self] = src[g]
finally:
g.set_directed(is_directed)
g.set_edge_filter(efilt[0], efilt[1])
g.set_vertex_filter(vfilt[0], vfilt[1])
if g is not self:
self.set_directed(self_is_directed)
self.set_edge_filter(self_efilt[0], self_efilt[1])
self.set_vertex_filter(self_vfilt[0], self_vfilt[1])
return ret return ret
# degree property map # degree property map
......
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