ENH: implement np.einsum for MaskedNDArray - #16725
neutrinoceros wants to merge 1 commit into
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.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
np.einsum for MaskedNDArray
mhvk
left a comment
There was a problem hiding this comment.
Some initial comments, mostly to suggest an easier way to calculate the final mask...
| raise NotImplementedError | ||
|
|
||
| else: | ||
| kwargs_with_out["out"] = out.unmasked.view(np.ndarray) |
There was a problem hiding this comment.
Why the .view(np.ndarray)? If this is, say, a Quantity, then I think it should still be dispatched on that.
| mask = np.full_like(input, fill_value=False, dtype=bool) | ||
| return Masked(input, mask=mask) | ||
|
|
||
| mas = tuple(as_masked_ndarray(op) for op in operands) |
There was a problem hiding this comment.
I think you want arrays, masks = _get_data_and_masks(*operands)?
|
|
||
| masks = tuple(ma.mask for ma in mas) | ||
|
|
||
| from collections import Counter |
There was a problem hiding this comment.
Are you sure this whole sequence is necessary? If we stick with that any masked element propagates correctly, then can we not just use the same trick as for matmul in __array_ufunc__:
astropy/astropy/utils/masked/core.py
Lines 780 to 794 in 0ea3682
(Note that it did take me quite a while to realize this might work...)
| result = retv | ||
|
|
||
| # TODO: understand what the third item is supposed to be | ||
| return result, mask, None |
There was a problem hiding this comment.
Third item is a possible out parameter (which should be Masked)
|
Thanks for this first round @mhvk, and especially for suggesting a simpler impl. I was initially happy with my current strategy, but the last failing test made me think that maybe I actually painted myself into a corner. |
|
Bonnes vacances! |
|
I don't think I'll have time to return to this before the feature freeze so let's move it to 7.1 |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
|
Still planning to come back to this eventually... let me rebase the branch and disable autoclosing |
5d2cd53 to
10f1539
Compare
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
Description
This is a work in progress.
Rationale:
np.einsumforMaskedNDArrayis currently blocking ENH: include exclusive values from IERS_B in IERS_Auto (blocked by #16725) #16070 and @mhvk has expressed interest in supporting itNow, clearly, I didn't know what I was getting myself into when I proposed doing this, but I'm making progress. I'm opening this draft PR at a relatively early stage so it doesn't get lost in my constant context-switching dance.
At the time of writing, only the last test is failing. Fixing this is my next priority.