Commit 1f6f566f authored by Tiago Peixoto's avatar Tiago Peixoto

Do not use filter stash internally, in favour of graph views

parent 7a401052
...@@ -787,14 +787,12 @@ def group_vector_property(props, value_type=None, vprop=None, pos=None): ...@@ -787,14 +787,12 @@ def group_vector_property(props, value_type=None, vprop=None, pos=None):
for i, p in enumerate(props): for i, p in enumerate(props):
if k != "g": if k != "g":
g.stash_filter(directed=True, reversed=True) u = GraphView(g, directed=True)
g.set_directed(True) u.set_reversed(False)
g.set_reversed(False) libcore.group_vector_property(u._Graph__graph, _prop(k, g, vprop),
libcore.group_vector_property(g._Graph__graph, _prop(k, g, vprop),
_prop(k, g, p), _prop(k, g, p),
i if pos == None else pos[i], i if pos == None else pos[i],
k == 'e') k == 'e')
g.pop_filter(directed=True, reversed=True)
else: else:
vprop[g][i if pos is None else pos[i]] = p[g] vprop[g][i if pos is None else pos[i]] = p[g]
return vprop return vprop
...@@ -853,14 +851,12 @@ def ungroup_vector_property(vprop, pos, props=None): ...@@ -853,14 +851,12 @@ def ungroup_vector_property(vprop, pos, props=None):
raise ValueError("'props' must be of the same key type as 'vprop'.") raise ValueError("'props' must be of the same key type as 'vprop'.")
if k != 'g': if k != 'g':
g.stash_filter(directed=True, reversed=True) u = GraphView(g, directed=True)
g.set_directed(True) u.set_reversed(False)
g.set_reversed(False)
libcore.ungroup_vector_property(g._Graph__graph, libcore.ungroup_vector_property(g._Graph__graph,
_prop(k, g, vprop), _prop(k, g, vprop),
_prop(k, g, props[i]), _prop(k, g, props[i]),
p, k == 'e') p, k == 'e')
g.pop_filter(directed=True, reversed=True)
else: else:
if len(vprop[g]) <= pos[i]: if len(vprop[g]) <= pos[i]:
vprop[g].resize(pos[i] + 1) vprop[g].resize(pos[i] + 1)
......
...@@ -49,7 +49,7 @@ from __future__ import division, absolute_import, print_function ...@@ -49,7 +49,7 @@ from __future__ import division, absolute_import, print_function
from .. dl_import import dl_import from .. dl_import import dl_import
dl_import("from . import libgraph_tool_stats") dl_import("from . import libgraph_tool_stats")
from .. import _degree, _prop, _get_rng from .. import _degree, _prop, _get_rng, GraphView
from numpy import * from numpy import *
import numpy import numpy
import sys import sys
......
...@@ -407,21 +407,17 @@ def min_spanning_tree(g, weights=None, root=None, tree_map=None): ...@@ -407,21 +407,17 @@ def min_spanning_tree(g, weights=None, root=None, tree_map=None):
if tree_map.value_type() != "bool": if tree_map.value_type() != "bool":
raise ValueError("edge property 'tree_map' must be of value type bool.") raise ValueError("edge property 'tree_map' must be of value type bool.")
try: u = GraphView(g, directed=False)
g.stash_filter(directed=True) if root is None:
g.set_directed(False) libgraph_tool_topology.\
if root is None: get_kruskal_spanning_tree(u._Graph__graph,
libgraph_tool_topology.\ _prop("e", g, weights),
get_kruskal_spanning_tree(g._Graph__graph, _prop("e", g, tree_map))
_prop("e", g, weights), else:
_prop("e", g, tree_map)) libgraph_tool_topology.\
else: get_prim_spanning_tree(u._Graph__graph, int(root),
libgraph_tool_topology.\ _prop("e", g, weights),
get_prim_spanning_tree(g._Graph__graph, int(root), _prop("e", g, tree_map))
_prop("e", g, weights),
_prop("e", g, tree_map))
finally:
g.pop_filter(directed=True)
return tree_map return tree_map
...@@ -1166,30 +1162,27 @@ def shortest_distance(g, source=None, target=None, weights=None, max_dist=None, ...@@ -1166,30 +1162,27 @@ def shortest_distance(g, source=None, target=None, weights=None, max_dist=None,
max_dist = 0 max_dist = 0
if directed is not None: if directed is not None:
g.stash_filter(directed=True) u = GraphView(g, directed=directed)
g.set_directed(directed) else:
u = g
if target is None: if target is None:
target = -1 target = -1
try: if source is not None:
if source is not None: pmap = g.copy_property(u.vertex_index, value_type="int64_t")
pmap = g.copy_property(g.vertex_index, value_type="int64_t") libgraph_tool_topology.get_dists(g._Graph__graph,
libgraph_tool_topology.get_dists(g._Graph__graph, int(source),
int(source), int(target),
int(target), _prop("v", g, dist_map),
_prop("e", g, weights),
_prop("v", g, pmap),
float(max_dist))
else:
libgraph_tool_topology.get_all_dists(u._Graph__graph,
_prop("v", g, dist_map), _prop("v", g, dist_map),
_prop("e", g, weights), _prop("e", g, weights), dense)
_prop("v", g, pmap),
float(max_dist))
else:
libgraph_tool_topology.get_all_dists(g._Graph__graph,
_prop("v", g, dist_map),
_prop("e", g, weights), dense)
finally:
if directed is not None:
g.pop_filter(directed=True)
if source is not None and target != -1: if source is not None and target != -1:
dist_map = dist_map[target] dist_map = dist_map[target]
...@@ -1511,8 +1504,7 @@ def is_planar(g, embedding=False, kuratowski=False): ...@@ -1511,8 +1504,7 @@ def is_planar(g, embedding=False, kuratowski=False):
.. [boost-planarity] http://www.boost.org/libs/graph/doc/boyer_myrvold.html .. [boost-planarity] http://www.boost.org/libs/graph/doc/boyer_myrvold.html
""" """
g.stash_filter(directed=True) u = GraphView(g, directed=False)
g.set_directed(False)
if embedding: if embedding:
embed = g.new_vertex_property("vector<int>") embed = g.new_vertex_property("vector<int>")
...@@ -1524,12 +1516,9 @@ def is_planar(g, embedding=False, kuratowski=False): ...@@ -1524,12 +1516,9 @@ def is_planar(g, embedding=False, kuratowski=False):
else: else:
kur = None kur = None
try: is_planar = libgraph_tool_topology.is_planar(u._Graph__graph,
is_planar = libgraph_tool_topology.is_planar(g._Graph__graph, _prop("v", g, embed),
_prop("v", g, embed), _prop("e", g, kur))
_prop("e", g, kur))
finally:
g.pop_filter(directed=True)
ret = [is_planar] ret = [is_planar]
if embed is not None: if embed is not None:
......
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