I am trying to use purge_vertices() with a vertex filter to efficiently remove vertices from a graph. I am seeing different behavior in version 2.2.18 and 2.2.25, both as prebuilt packages for Ubuntu precise (current "graph-tool" and "python-graph-tool" packages, respectively)

I have a simple example script attached which shows the behavior. If I run with graph-tool 2.2.18, it works without complaint, e.g.:

$ python graph-tool-play2.py
graph_tool version 2.2.18 (commit 83bb8a49, Tue Nov 13 00:57:29 2012 +0100)
pruning 11
pruning 13
pruning 14
pruning 19
pruning 23
pruning 26
pruning 46
pruning 47
pruning 48
pruning 52
pruning 63
pruning 81
pruning 93
pruning 97
complete

If I run with python-graph-tool 2.2.25, I get a TypeError, e.g.:

$ python graph-tool-play2.py
graph_tool version 2.2.25 (commit feec13d9, Mon Sep 2 00:01:39 2013 +0200)
pruning 10
pruning 12
pruning 13
pruning 18
pruning 22
pruning 25
pruning 45
pruning 46
pruning 47
pruning 51
pruning 62
pruning 80
pruning 92
pruning 96
Traceback (most recent call last):
  File "graph-tool-play2.py", line 59, in <module>
g.purge_vertices() # MJH this will die in graph-tool 2.2.25 with a TypeError. Works in 2.2.18. File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line 1838, in purge_vertices
    new_g = Graph(self, prune=(True, False, False))
File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line 1109, in __init__
    vorder.fa = numpy.arange(gv.num_vertices())
File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line 561, in <lambda>
    lambda self, v: self.__get_set_f_array(v, False),
File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line 556, in __get_set_f_array
    a[m] = v
TypeError: array cannot be safely cast to required type

Why would this fail in 2.2.25? It's entirely possible that I am missing something basic about how to fly graph-tool.

Any clues appreciated!

Cheers,

Mark.

#! /usr/bin/env python

from numpy.random import *
seed(42) # gt convention ;-)

import graph_tool as gt

print 'graph_tool version %s' % (gt.__version__)

g = gt.Graph()

# create graph with vertex properties 'foo' and 'prune' and edge
# property 'bar'

v_foo = g.new_vertex_property('float')
v_prune = g.new_vertex_property('bool')

e_bar = g.new_edge_property('float')

# add some vertices, and connect each in sequence with an edge
N = 100

v = g.add_vertex()
v_foo[v] = 0
v_prune[v] = False

vlist = [v]

for i in range(1, N):
    last_v = v

    v = g.add_vertex()
    v_foo[v] = i
    v_prune[v] = False

    e=g.add_edge(v, last_v)
    e_bar[e] = randint(0, 100)

    vlist.append(v)

# internalize the properties
g.vertex_properties['foo'] = v_foo
g.vertex_properties['prune'] = v_prune
g.edge_properties['bar'] = e_bar

# save graph 'before'
g.save('graph-tool-play2.xml')

#graph_draw(g, output_size=(1000, 1000), output='graph-tool-play2.png')

# now mark some nodes to be purged
for v in g.vertices():
    if randint(0, 100) < 10:
        v_prune[v] = True
        print 'pruning %d' % (v)

# purge using vertex filter and purge_vertices()
g.set_vertex_filter(v_prune, inverted=True)
g.purge_vertices() # MJH this will die in graph-tool 2.2.25 with a TypeError. Works in 2.2.18.

# save graph 'after'
g.save('graph-tool-play2-purged.xml')
        
#graph_draw(g, output_size=(1000, 1000), output='graph-tool-play2-purged.png')

print 'complete'
_______________________________________________
graph-tool mailing list
[email protected]
http://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to