#18250: G.triangles_count speedup
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:
  ncohen                 |       Status:  needs_review
           Type:         |    Milestone:  sage-6.7
  enhancement            |   Resolution:
       Priority:  major  |    Merged in:
      Component:  graph  |    Reviewers:
  theory                 |  Work issues:
       Keywords:         |       Commit:
        Authors:         |  fa6115dc6cdea907dad9c2cd69668f5e71660024
  Nathann Cohen          |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  public/18250           |
   Dependencies:         |
-------------------------+-------------------------------------------------
Changes (by ncohen):

 * status:  needs_info => needs_review


Comment:

 Yooooooooooooooo,

 > Small commit for documentation at `public/18250`.

 Oh, right. Thanks.

 > The algorithm `'iter'` returns `int` while `dense_copy` returns
 `Integer`. This would better be uniform.

 Done.

 > You always perform a copy?! Isn't it possible to have a graph whose
 backend is already a `static_sparse_graph` or a `static_dense_graph`?

 Well, in this case copies are eally cheap, so I personally prefer a
 simpler code to one that avoids that copy.

 Still, I implemented it. There is a 'trick' somewhere:

 1) I first build a copy of the graph with `G.copy(immutable=True)` (which
 makes no copy if the graph is already immutable), then access its internal
 data structure

 2) If I do `g[0] = G.copy(immutable=True)._backend._cg.g[0]` I get a
 segfault because G.copy() is immediately deallocated. So I first do `G =
 G.copy(immutable=True)._backend`, and *then* access its internal data.

 Fortunately the copy `G` is not deleted until the end of the function. If
 Cython ever notices that (as far as it is concerned) it is never used
 again in the function, then it will be deallocated and we will get a
 segfault again.

 Nathann

--
Ticket URL: <http://trac.sagemath.org/ticket/18250#comment:5>
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