On 21.09.2016 14:53, Patrick Totzke wrote:
>>> Is there a better way to filter my graphs than writing a custom
>>> `GraphView` subclass for it?
>>
>> You can just use the set_edge/vertex_filter() methods of Graph.et
> 
> Yes, but as far as I understand one cannot add multiple vertex-filters
> right? I mean in order to solve my problem recursively on subgraphs,
> I can of course set a filter and then recur. But then "setting a
> filter" would amount to amending an already existing one...

You can just keep several copies of the mask, and compose them by hand:

    old_mask = g.get_vertex_filter()[0]
    mask = old_mask.copy()
    for v in sub_graph_vertices:
        mask[v] = False
    g.set_vertex_filter(mask)
    # now g does no longer contains those vertices

It is easy to do this recursively, and it amounts to what is actually done
with GraphView, although it is less elegant.

> Another related question: my algorithm could potentially parallelize the
> recursive calls dealing with subgraphs.
> If I use filters as you suggest to identify subgraphs, does the fact
> that concurrent recursive calls handle the same graph object with
> different filters cause any problems?

Yes, it would cause problems, since you would have only one graph instance,
whereas with GraphView it would not.

However, this is an entirely moot point, since you cannot truly parallelize
things in (pure) Python. You would get nothing for it.

> Could you point me towards example (python) code that utilizes parallel
> threads? Or is this done only on a libboost level?

It can't be done in Pure python, only if you drop to C/C++. You can read
more here: https://wiki.python.org/moin/GlobalInterpreterLock

> BTW: I believe there is a typo in the docstring for `Graph.set_filters`:
>   "Only the vertices and edges with value different than True are kept in
>    the filtered graph"
> Shouldn't it say values different from `False`, as in `set_vertex_filter`?

Yes, it is a typo. Thanks for catching it.

Best,
Tiago

-- 
Tiago de Paula Peixoto <ti...@skewed.de>

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
graph-tool mailing list
graph-tool@skewed.de
https://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to