graph_tool: access vertex/edge property faster

606 views Asked by At

I'd like to speed up the vertex/edge property access process.

For vertex property access, I find one way to optimize however for edge property access, it is not so trivial to me.

The idea for vertex property is to modify the internal array (a property) directly.

For example

vfilt = g.new_vertex_property('bool')
for i in range(9999): 
    vfilt.a[int(i % n)] = random.randint(0, 1)

(note vfilt.a not vfilt)

instead of using:

vfilt = g.new_vertex_property('bool')
for i in range(9999): 
    vfilt[int(i % n)] = random.randint(0, 1)

however, for edge, I'm not sure about the mapping between edge and its internal index in the property array.

My question is:

  • how to optimize edge property access?
  • is there other ways to optimize vertex property?
1

There are 1 answers

0
Peaceful On

How about

for e in g.edges():
    vfilt[e] = random.randint(0, 1)

Similarly, for vertices:

for v in g.vertices():
    vfilt[v] = random.randint(0, 1)