-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Rewrite core in C using Numpy ufuncs #110
Conversation
a1e073e
to
f307f89
Compare
4e5a708
to
6ee0e69
Compare
There are a few Python 2 issues with this patch. Is it OK to drop Python 2 support from this package? |
Sure, if you want this in quickly, and you can keep Python 2 support without much extra work, OK to add |
As a result, broadcasting across nside and ipix is supported automatically. Fixes astropy#72, closes astropy#75.
@lpsinger - Can you have a look at the CI fails?
Apart from those, there's a few fails because Astropy isn't compatible with Matplotlib 3.0:
@astrofrog - What should be done about those? Probably tweak the versions in |
Oops, I didn't refresh the page, so was looking at an older status. The only CI fail that remains here is the unrelated one for MPL 3.0. @astrofrog - Could you please do a code review on this PR? |
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.
@lpsinger - Two small inline comments from me.
Overall this looks good and I'm +1 to merge.
But I'm not really familiar with Python C interfacing much, so @astrofrog - if you could review this, or ping someone from the Astropy team that knows C / Numpy / ufunc well, that would be good. Although if no-one has time, I think we could also just merge this in for now, I don't really have a concern.
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.
This looks good to me - the only thing perhaps missing (unless I didn't see it) would be a test to demonstrate the broadcasting functionality of the ufuncs. Otherwise, our tests are pretty extensive, so if they all pass then this is good to go.
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 see that you have this everywhere in Python when calling into C:
if _validate_order(order) == 'ring':
func = _core.lonlat_to_healpix_ring
else: # _validate_order(order) == 'nested'
func = _core.lonlat_to_healpix_nested
and then there is the order_funcs
in the C code with the IMO quite complex way to select the func
.
I really don't know, just as a question: is there a simpler way to do this, avoiding the whole *data
and order_funcs
stuff? E.g. by having a wrapper function that selects or helper function that applies the conversion? Related: I also see strcmp
in one place - would int
there to select ordering be better that str
?
One small suggestion: you use -1
in many places as "NA" placeholder in the C code, right? Maybe make that a global constant instead of the hard-coded -1 for better readability?
@lpsinger - Do as you think best, and go ahead and merge this in.
Should we make a release to see if this works OK in package distribution?
for (i = 0; i < n; i ++) | ||
{ | ||
int64_t pixel = *(int64_t *) &args[0][i * steps[0]]; | ||
int nside = *(int *) &args[1][i * steps[1]]; |
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.
Why do we have mostly int64_t
for integers, but then int nside
? I guess it doesn't matter because nside
will fit in an int
, but wouldn't it be simpler to have int64_t
everywhere so that we never have to think about what to put as type? - just a thought. Do as you think best and 👍 to merge this in.
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.
Such a change would affect the astrometry.net code as well, so that's a bigger question.
In Healpy, the ordering is treated as a flag ( I judged that the user would never want to pass the ordering as a vector, that it would never need to be broadcastable, and I tried to avoid the potential performance hit of a conditional in the inner loop. However, the function pointer stuff might be equally costly, and is a bit less readable. We could use preprocessor macros to make two versions of each loop function, one for each ordering. That would be more performant, but also more code and less readable code. Another option is that the _core module could wrap
We could use
Done. |
I tried some of my own code that uses astropy-healpix through reproject, and the results looked good. |
That does sound a bit simpler and easier to read to me. Agreed that the broadcasting feature isn't needed here, and performance is probably very similar, so the only improvement here would be code simplicity, not needing to know about the not well-documented @lpsinger @astrofrog - What do you think? Just keep as-is or change to this? |
As a result, broadcasting across nside and ipix is supported automatically.
Fixes #72, closes #75.