New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Easier handling of vertex labels in graph backends #18346
Comments
New commits:
|
Branch: public/18346 |
Commit: |
This comment has been minimized.
This comment has been minimized.
comment:3
Hello,
Vincent |
comment:5
Hello,
I do not think that it is if you do not modify them. Some functions (like isomorphism test) use it directly. The guy who wrote the code that does that knew what he was doing, unfortunately he is the only one
Not that I know. I am not sure that I remember exactly what they do either. What I remember is that not all vertices have an associated label, so that you don't spend your time playing with a dictionary when your graph is defined over integers. This being said, I plan to rewrite all this (and of course the new code will have a proper documentation). I spent several hours thinking of how this should all be done, and my hardest constraint was that the changes should be "reviewable". Which is not very easily achieved when you plan to merge two classes together The 'first step' was #18185, the second is this one (or #18317, but that's only doc). Then I will turn NetworkX backend into a CGraph, and deprecate a lot of things in there. And then... Merge the classes
Okay. Well, I don't think I did anything like that but I may have met such a line somewhere. Really, this does not matter for the moment: this code will be heavily rewritten. Nathann |
comment:6
Hello, Replying to @nathanncohen:
Actually you do since
Hum + cdef int get_vertex(self, object u) except ? -2
+ cdef object vertex_label(self, int u_int) this would better be cdef int get_vertex(self, u) except ? -2
cdef vertex_label(self, int u_int) Vincent |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:8
Yo !
Oh really? But perhaps the dictionary does not contain the integers then? Anyway, does not matter much.
The aim of this ticket is to merge CGraph and Backend together. All that "backend" does is forward everything to CGraph. But I certainly cannot do all of this at once, it would be impossible to review. Plus because of the problems I met when writing this branch, I know that I should be wary of the isomorphism test code which works at a lower level than I expected.
Fixed. Actually, those are the lines that I moved from functions to methods. You will find (almost) the same lines with a '-' in front of them, a couple of lines above. Nathann |
comment:9
Replying to @nathanncohen:
Will you keep these Vincent |
comment:10
I have no idea for the moment. If there is something you want to change, it really cannot hurt. Nathann |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:12
I win some very precious nano seconds and add a tiny bit of documentation for Vincent |
comment:13
Heuuuuuuu... Sorry Vincent but I am not really sure that what this code needs is 10 more lines to convert integer types from one to another.... And if you remove some 'object', please remove them from the |
comment:14
If this kind of cast from !Python/!Sage integer is really costly, perhaps we should have a cdef function that does it somewhere? Do I make a mistake if I say that you wrote this code in order to avoid having to raise an exception in many cases ? Nathann |
comment:15
Replying to @nathanncohen:
That's a possibility, but it is not clear what should be the signature of the function. What if it fails?
It is not only that: calling directyl |
comment:16
Yo !
Well, if you can turn it into an independent function in some other module (something integer-related) then no problem. This code is much more in need of clarity than nanoseconds at the moment Nathann |
comment:18
Hello, Do whatever you want with Vincent |
comment:19
If you do not plan to turn the integer tests into a an independent function, then can you discard it? |
comment:20
Replying to @nathanncohen:
yes |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:22
I am done with reviewing your commits and they are fine. So if |
Reviewer: Vincent Delecroix |
comment:23
Yoooooooooo !
Oh. Great, thanks !! I was reviewing that commit. I should be done in 10 minutes. Nathann |
comment:24
If you feel like messing with a new subfolder of src/, I cleaned a couple of things from finance/ in #18355 |
comment:25
Okayokay, it's all good. Thank you very much for your help with these painful patches Nathann |
comment:26
|
comment:27
Replying to @nathanncohen:
The proper solution to "convert" a Python object
see
Vincent |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Dependencies: #18317 |
Changed branch from public/18346 to |
This ticket addresses the following problem:
check_vertex
. They are always called with the same arguments, which areall 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
andStaticSparseGraph
) andGenericGraphBackend
are turned into cdef classes.The three functions
get_vertex
,vertex_label
,check_vertex
becomemethods 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 directlyG._backend._cg
.This should have been sufficient, but there were (unexpected) consequences:
work), and the doctests do not pass if that does not work. Consequently, I
implemented a unique
__reduce__
function inGenericGraphBackend
whichhandles 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
andGenericBackend
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
Depends on #18317
CC: @sagetrac-borassi @dcoudert @darijgr @videlec
Component: graph theory
Author: Nathann Cohen
Branch/Commit:
6ffbb05
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/18346
The text was updated successfully, but these errors were encountered: