On 02/06/2013 09:40 PM, Uldis Bojars wrote: > On Fri, Jan 25, 2013 at 12:56 AM, Tiago de Paula Peixoto > <[email protected]> wrote: >>> >>> 1) extracting vertex clusters based on values in vertex property map? >> >> You can improve the performance by avoiding repeated python function >> calls for each vertex. One way to do this is to use array >> expressions. For instance, instead of doing: >> >> gv1 = gt.GraphView(g, vfilt = lambda v: v_prop[v] == cl_num) >> >> you could do: >> >> gv1 = gt.GraphView(g, vfilt = v_prop.a == cl_num) >> >> The second option should be significantly faster for larger graphs. > > Awesome! Thanks a lot, this solved the problem. > > Where could I find more information about the v_prop.a == cl_num part? > It might be useful in other cases of working with graph-tool, but > first need to understand it. Is it a part of NumPy?
Yes, v_prop.a returns a view of the property map as a Numpy array. Numpy supports so-called "array expressions", which translates to simple C loops. So when you do v_prop.a == cl_num, this returns an array of boolean values, which is computed in a tight C loop. This array is used as-is by the GraphView constructor, which uses it as a filter. Thus, no python loop is ever performed. In the first version, however, a function is passed to the constructor, which is called on each vertex to build a filter, resulting in a much slower performance. Cheers, Tiago -- Tiago de Paula Peixoto <[email protected]>
signature.asc
Description: OpenPGP digital signature
_______________________________________________ graph-tool mailing list [email protected] http://lists.skewed.de/mailman/listinfo/graph-tool
