#18346: Easier handling of vertex labels in graph backends
-------------------------+-------------------------------------------------
       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:         |  25765bb3c4cb4c5f49e5078d7e6e3968c62310e1
  Nathann Cohen          |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  public/18346           |
   Dependencies:         |
-------------------------+-------------------------------------------------
Description changed by ncohen:

Old description:

> This ticket addresses the following problem:
>
>     In the `CGraph` backends, three `cdef` functions are used all the
> time to
>     deal with vertex labels, i.e. `get_vertex`, `vertex_label`,
>     `check_vertex`. They are always called with the same arguments, which
> are
>     all attributes of the backend that calls it. They should be method,
> so that
>     the arguments are not needlessly repeated.
>
> What this branch does:
>
> - The `CGraph` backends (i.e. `SparseBackend`, `DenseBackend` and
>   `StaticSparseGraph`) and `GenericGraphBackend` are turned into cdef
> classes.
>
> - The three functions `get_vertex`, `vertex_label`, `check_vertex` become
>   methods of `CGraphBackend`
>
> - It adds a method `CGraphBackend.c_graph()` to get the two cdef
> attributes
>   `_cg` and `_cg_rev`. Turns out that some code in Sage accesses directly
>   `G._backend._cg`.
>
> This should have been sufficient, but there were (unexpected)
> consequences:
>
> - There is no automatic pickling for cdef classes (as instrospection does
> not
>   work), and the doctests do not pass if that does not work.
> Consequently, I
>   implemented a unique `__reduce__` function in `GenericGraphBackend`
> which
>   handles the pickling for all backends (sparse/dense/static/networkx).
> It also
>   removes some duplicated code as a result.
>
> This makes the code a bit clearer (and it is needed). Also, moving this
> pickling
> function above is good for the future, for there will be many
> modifications in
> the future to the data structures in Sage: I plan to merge `CGraph` and
> `GenericBackend` into only one class (but that's for later).
>
> Nathann

New description:

 This ticket addresses the following problem:

     In the `CGraph` backends, three `cdef` functions are used all the time
 to
     deal with vertex labels, i.e. `get_vertex`, `vertex_label`,
     `check_vertex`. They are always called with the same arguments, which
 are
     all attributes of the backend that calls it. They should be method, so
 that
     the arguments are not needlessly repeated.

 What this branch does:

 - The `CGraph` backends (i.e. `SparseBackend`, `DenseBackend` and
   `StaticSparseGraph`) and `GenericGraphBackend` are turned into cdef
 classes.

 - The three functions `get_vertex`, `vertex_label`, `check_vertex` become
   methods of `CGraphBackend`

 - It adds a method `CGraphBackend.c_graph()` to get the two cdef
 attributes
   `_cg` and `_cg_rev`. Turns out that some code in Sage accesses directly
   `G._backend._cg`.

 This should have been sufficient, but there were (unexpected)
 consequences:

 - There is no automatic pickling for cdef classes (as instrospection does
 not
   work), and the doctests do not pass if that does not work. Consequently,
 I
   implemented a unique `__reduce__` function in `GenericGraphBackend`
 which
   handles the pickling for all backends (sparse/dense/static/networkx). It
 also
   removes some duplicated code as a result.

 This makes the code a bit clearer (and it is needed). Also, moving this
 pickling
 function above is good for the future, for there will be many
 modifications in
 the future to the data structures in Sage: I plan to merge `CGraph` and
 `GenericBackend` into only one class (but that's for later).

 Nathann

 P.S.: The branch is built to be reviewed commit by commit. In particular,
 the renamed file appears as trivial when looking at the first commit, but
 as a lot of + and - when looking at the branch's diff

--

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