Thanks a lot for the explanation! So is there a best way to have access to the properties?
On 18 July 2014 21:39, Tiago de Paula Peixoto <[email protected]> wrote: > On 07/16/2014 05:44 PM, Flavien Lambert wrote: > > On the same topic, I did not find the function for getting the edge > > from the edge index. There is one for vertices like vertex(n) but for > > edges? > > There is no such function, and this is related to the speed difference > you are seeing. The edges are not stored in one big vector, and thus > cannot be addressed simply by its index. Instead, they are stored in > different vectors across all nodes (i.e. and adjacency list), and thus > one needs to iterate first through the vectors. > > Now lets look at your code: > > > _edges = [_e for _e in _network.edges()] > > %time for _e in _network.edges() : a = _speeds[_e] > > > > _speedDict = {} > > for _e in _edges : > > _speedDict[_network.edge_index[_e]] = _speeds[_e] > > _indexes = [_network.edge_index[_e] for _e in _network.edges()] > > %time for _n in _indexes : a = _speedDict[_n] > > What makes the second loop slower has little to do with property maps vs > dicts, but instead with the loop over the Graph.edges() iterator and the > loop ofter the list you created in the second part. Whenever you loop > over the edges, not only is the loop slightly slower because it is not a > simple list, but a "list of lists", but also (more importantly) because > it has to *create* edge descriptor objects at each iteration! In the > second loop you created these objects and stored them in a list, and > then looped over this list, which does not involve object creation, and > is therefore much faster. > > Best, > Tiago > > -- > Tiago de Paula Peixoto <[email protected]> > > > _______________________________________________ > graph-tool mailing list > [email protected] > http://lists.skewed.de/mailman/listinfo/graph-tool > >
_______________________________________________ graph-tool mailing list [email protected] http://lists.skewed.de/mailman/listinfo/graph-tool
