-
Notifications
You must be signed in to change notification settings - Fork 2
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
Auto-generated cython_numpy wrapper #6
base: master
Are you sure you want to change the base?
Conversation
For later automation, it is easier to have all inputs vectorized.
Just because one of its parameters is an input and an output at the same time. And it also uses the complex eraASTROM structure.
…instead of empty() and copyto()
Thanks for working on this! I'm cc-ing @taldcroft, @mdboom and @embray as they might be interested in reviewing this. |
def __init__(self, name, source_path): | ||
self.name = name | ||
self.pyname = name.split('era')[-1].lower() | ||
self.filename = name.split("era")[-1].lower()+".c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm following along correctly, this means that it's opening the .c
file to find the signature for the function? It should probably open the .h
file, as a system installation of erfa
will generally have the headers, but not the source code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. The reason for parsing the .c
file instead is that SOFA/ERFA has properly documented the input/output status of each parameter. It would also let us generate the documentation for each auto-generated function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah -- having gone and looked at the SOFA/ERFA code, I see what you're saying now, and I see why that's the only real alternative. Not to sound like a curmudgeon, but SOFA is totally doing it wrong. The .h files should include the documentation, not the .c files.
At the end of the day, it probably matters little, because I suspect we would generate the .pyx
file, and its resulting .c
file through Cython, and ship that in our tarball, so the end user won't need the SOFA/ERFA .c
files to build astropy. But it might be worth a note to the SOFA folks about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree with you on the documentation location. We could also relocate the documentation when deriving ERFA from SOFA. This could help those that will use or develop with ERFA directly.
Will open a separate issue against ERFA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You already did! :)
liberfa/erfa#24
Cool stuff! |
Thanks for working on this -- hope my comments don't seem to nitpicky -- indeed I think this is a really good approach overall. |
http://jinja.pocoo.org is very nice indeed! |
This looks very nice! As a further test, it would be interesting to replace the Cython wrappers for SOFA that are already in Astropy with the auto-generated versions and see if the Astropy tests still pass. The routines are in https://github.com/astropy/astropy/blob/master/astropy/time/erfa_time.pyx |
Good idea! I had a quick look at |
@mdboom - see #2803 where I just made the same comment before you said this. I think it makes sense to do something like this:
However, we only assign "long-form" names manually for function we actually want to use (it should be a trivial task, like just adding an entry to a dictionary). In the docs, the function would live under its long-from name if it has one, and if not, it's standardized name. An alternative is to have these be separate namespaces. I.e., the long form names live in |
@jwoillez - This is fantastic! In addition to @astrofrog's suggestion, I suggest you also try timing the current tests vs. the approach here. That is, see if one runs noticeably slower or faster than the other. I would think they shouldn't "in theory", but theory and practice often disagree... Perhaps you can just by-hand implement the mapping from what this generates to the current names, just so we can see if there are any major compatibility or speed problems? If not, I think I'm happy to just say lets go with this approach! |
One procedural question for the crowd: do we want these to be auto-generated a la how we generate Cython code? That is, as part of the build process, or is this a script that should be just run by hand when we want to update the source code in astropy? I tend towards the latter, because then we don't need to put jinja in |
If we go forward with longer function names, I would also manually add input/output specifications for the functions arguments. The use of the documentation to deduce this seems rather fragile. I am not quite happy yet with the way matrices and vectors are handled. At the moment, you have to use rec arrays. A tri-vector Last, I will be away for a month or so. Be patient, or take over! ;) |
Ah, good point about the input/output specifications. More generally, it probably makes sense to write actual docstrings for the "longer name" versions. When I think about it, this may just be best to be kept simple by just doing something like:
In case someone else wants to finish this while you're away, @jwoillez, one clarification question: are you saying the need for a matrix comes from a limitation of cython's conversion to c arrays, or with how ERFA consumes arrays? |
@jwoillez - just to check, are you still able to work on this? I think it is going to be very important to have this working since some of the big improvements in astropy.coordinates are going to rely on this. Would it help if we organize a hangout with a few people interested in this to talk over the options? It does seem like this is the way to go, and we just need to decide on some details? |
Oh, I probably should have mentioned I've been working on porting this to astropy. See astropy/astropy#2992 . One major difference: astropy uses the all-one-file |
Do we need to use the all-in-one file? I've never personally understood the motivation for that -- it makes using an upstream ERFA have an extra step that maybe we don't need to do either. |
@mdboom - because it deals more specifically with astropy/astropy#2992, I'll respond to your question there. (This PR currently does not handle the single-file case). |
Very late to the game here, but this is wonderful! Reading the long thread, my only comment would be not to worry about long names for this PR -- for Of course, for astropy, it is probably good to at least have @eteq's "standardized" names. I'm less in favor of long names, since it then forces us to think of a standard when people might as well get used to the IAU mandated one (even if we think it is not necessarily a good one). And within individual subpackages such as OK, I better go try it! |
Trying to understand the
This seems to a problem of long vs short integers (
|
@mhvk - this is actually better addressed in astropy/astropy#2992 now - that has a lot of additional work on top of this. And just to be clear, the plan is not necessarily to include anything like this in ERFA itself. The tentative thought is for |
@eteq - OK, and nice to see that you already solved this particular problem! I think it is slightly a pity to not give the python bindings separately -- better to give people freedom to just use a small part of astropy without downloading the whole package -- but as I'm not the one doing the work and personally will only use it through astropy anyway, take this with a pinch of salt. That said, if people were to want to just use the bindings, would the |
@mhvk - the main issue in my mind is the management overhead, because we need an "official" version for astropy. My thinking is that we don't want to include it with That said, we could consider altering the scope of |
@eteq - OK, let's minimize overheads for everybody! Ideally, just point to the |
@mhvk - oh, yeah, that's a good point - anyone who wants it by itself can just pull out our |
I added a new wrapping experiment 'cython_numpy_auto' that adds cython code auto-generation for the same approach as 'cython_numpy'.
To test drive:
python cython_generator.py
in directorycython_numpy_auto
python setup.py install --user
or similar command.python test_erfa.py
in directorytests
.Note:
You must have the
erfa
sources installed next toerfa-wrapping-experiments
for the auto-generation to work.To Do List:
jinja2
erfam.h
erfa.h