-
Notifications
You must be signed in to change notification settings - Fork 48
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
Synchronize gwcs region with changes in jwst/romancal #517
Synchronize gwcs region with changes in jwst/romancal #517
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #517 +/- ##
==========================================
- Coverage 87.28% 87.26% -0.03%
==========================================
Files 22 21 -1
Lines 3821 3815 -6
==========================================
- Hits 3335 3329 -6
Misses 486 486 ☔ View full report in Codecov by Sentry. |
23200c5
to
0d1c288
Compare
gwcs/region.py
Outdated
D = np.linalg.det([u, v]) | ||
|
||
if np.allclose(D, 0, rtol=0, atol=1e2 * np.finfo(float).eps): |
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.
For 2x2 arrays _cross
may be more efficient than np.linalg.det
(less overhead). Same goes for allclose
. I would also suggest defining a constant at the top of the module like
_INTERSECT_ATOL = 1e2 * np.finfo(float).eps
instead of recomputing it every time.
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 you are correct that your "_cross
" method is faster at 2.56 ms vs 18.2 ms over 100,000 samples; however, both are faster than np.cross
at 54.3 ms over the same input set. If you do want to go with the special method then I think it should be renamed to reflect the fact it is not really a cross product as the cross product does not make sense in 2D, but rather its really just a determinant of the matrix induced by the vectors.
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 are correct about _cross
in 2D.
gwcs/region.py
Outdated
return np.allclose( | ||
np.linalg.det([u, v]), 0, rtol=0, atol=1e2 * np.finfo(float).eps | ||
) |
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.
same here and also on line 403.
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.
LGTM. Thanks!
Do we really need In [2]: import numpy as np
In [3]: x = 1.e-12
In [4]: %timeit np.allclose(x, 0, 0, 1e-6)
12.4 μs ± 15.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [5]: %timeit abs(x) < 1.e-6
23.6 ns ± 0.0665 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) |
Sure |
49667c3
to
4261b79
Compare
There are copies of
region.py
in both jwst and romancal. This PR brings the gwcs version in line with these versions, so they can be factored out.