#17385: Cleanup Graph.__init__ and DiGraph.__init__
----------------------------+-------------------------------------
   Reporter:  vdelecroix    |            Owner:
       Type:  enhancement   |           Status:  new
   Priority:  major         |        Milestone:  sage-6.5
  Component:  graph theory  |         Keywords:
  Merged in:                |          Authors:  Vincent Delecroix
  Reviewers:                |  Report Upstream:  N/A
Work issues:                |           Branch:
     Commit:                |     Dependencies:  #17384
   Stopgaps:                |
----------------------------+-------------------------------------
 While reading #17384, I thought that a global cleanup of `Graph.__init__`
 and `DiGraph.__init__` would be good. We implement:

 1)
 {{{
 - data = dict([u, list(data[u])] for u in data)
 + data = {u: list(v) for u,v in data.iteritems()}
 }}}

 2) call to `uniq` is bad since it calls a useless `sorted`: each
 appearance of `{{{len(uniq(X))}}}` is replaced with `{{{len(set(X))}}}`.

 3) `dict.iteritems` is more readable and faster
 {{{
 sage: d = {randint(0,1000): [randint(0,1000) for _ in range(10)] for _ in
 range(100)}
 sage: timeit("for i in d: j = d[i]", number=2000)
 2000 loops, best of 3: 9.75 µs per loop
 sage: timeit("for i,j in d.iteritems(): pass", number=2000)
 2000 loops, best of 3: 7.3 µs per loop
 }}}

 4) avoid iterating through the elements of the adjacency matrix when
 possible

 and more...

--
Ticket URL: <http://trac.sagemath.org/ticket/17385>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to