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
Ensure mask calculation is correct also for multi-op ufunc with scalars #15450
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
@nstarman - would you be able to have a look at this one as well? It is a really simple change, so should be easy. Thanks! |
Ufuncs with more than 2 operands (such as ``erfa.dtf2d``) now work | ||
also if all inputs are scalars and more than two inputs have masks. |
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.
Ufuncs with more than 2 operands (such as ``erfa.dtf2d``) now work | |
also if all inputs are scalars and more than two inputs have masks. | |
Ufuncs with more than 2 operands (such as ``erfa.dtf2d``) now also | |
work if all inputs are scalars and more than two inputs have masks. |
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.
Happy to change this, but perhaps only if there is also a code change? I think there is no worry about zip
.
"utc", iy.unmasked, im.unmasked, idy.unmasked, ihr.unmasked, imn, isc | ||
) | ||
expected_mask = np.array([True, False, True]) | ||
for res, res0, exp in zip(result, result0, expected): |
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.
Aren't these different lengths? So it's not iterating over all of result? As in won't this fail?
for res, res0, exp in zip(result, result0, expected): | |
for res, res0, exp in zip(result, result0, expected, strict=True): |
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 think this is OK: all of result
, result0
, and expected
are output from the ufunc, which returns a tuple of 3 elements, jd1
, jd2
, and status
, each of which can be an array or scalar.
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.
But then zipping them together means the zip only goes to end of the shortest iterator, which is result0
, right? Equivalent to result[0]
? So the for loop is only 1 element?
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.
No, result0 is a tuple with 3 entries, it is the same as (jd1[0], jd2[0], stat[0])
where (jd1, jd2, stat)
would be in result
. The ufunc always gives back a tuple of three (I think my nomenclature may have not been very helpful here!).
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! Good. So then each element of result0
is broadcast against each element of result
and everything works. Gotcha.
ihr = Masked([11, 12, 13], mask=[False, False, True]) | ||
imn = np.array([50, 51, 52]) | ||
isc = np.array([12.5, 13.6, 14.7]) | ||
result = erfa_ufunc.dtf2d("utc", iy, im, idy, ihr, imn, isc) |
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.
Are the later elements ever tested? See comments on the zip
unpacking below.
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! Might want to clean up variable names / add comments in the tests, but it's a minor point.
I think I'll just merge given other time constraints... Thanks for the quick review!!! |
This comment was marked as resolved.
This comment was marked as resolved.
…r multi-op ufunc with scalars
…450-on-v5.3.x Backport PR #15450 on branch v5.3.x (Ensure mask calculation is correct also for multi-op ufunc with scalars)
Need manual backport to v5.0.x. If you do not want to do that, then please change the milestone. Thanks! |
…r multi-op ufunc with scalars
Thanks, manual backport in #15460; it was not very tricky, thankfully. |
Backport PR #15450 on branch v5.0.x (Ensure mask calculation is correct also for multi-op ufunc with scalars)
Description
This pull request is to address a small bug where if a ufunc with more than 2 scalar
Masked
arguments was used, the resulting mask could not be calculated.Found in #15231