Skip to content

ENH: Add support to ma.dot() for non-2d arrays with strict=True#23322

Merged
mattip merged 6 commits intomainfrom
unknown repository
Mar 26, 2023
Merged

ENH: Add support to ma.dot() for non-2d arrays with strict=True#23322
mattip merged 6 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 3, 2023

No description provided.

@ghost ghost changed the title Add support to ma.dot() for non-2d arrays with strict=True ENH: Add support to ma.dot() for non-2d arrays with strict=True Mar 3, 2023
@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 3, 2023

Was there a corresponding issue, or was this triggered by noticing the comments in the code?

I am wondering if this has a wider audience fro the fix.

numpy/ma/core.py Outdated
Comment on lines +7830 to +7854
a = array(a, subok=False)
if a.ndim != 2:
raise NotImplementedError("mask_rowcols works for 2D arrays only.")
m = getmask(a)
# Nothing is masked: return a
if m is nomask or not m.any():
return a
maskedval = m.nonzero()
a._mask = a._mask.copy()
if not axis:
a[np.unique(maskedval[0])] = masked
if axis in [None, 1, -1]:
a[:, np.unique(maskedval[1])] = masked
return a

if axis is None:
return _mask_propagate(a, axis=(0, 1))
elif axis == 0:
return _mask_propagate(a, axis=1)
else:
return _mask_propagate(a, axis=0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes don't seem to be necessary for the PR. Unless I'm wrong, it'd be best if you left this to a separate PR.

@MatteoRaso
Copy link
Copy Markdown
Contributor

I am wondering if this has a wider audience fro the fix.

I don't have a stake in this, but if Numpy's going to have an ma.dot function, I think it should have the same capabilities as the normal dot function.

# with higher dimension
if strict and (a.ndim == 2) and (b.ndim == 2):
a = mask_rowcols(a, 0)
b = mask_rowcols(b, 1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess mask_rowcols can now be moved to numpy/ma/extras.py rather than live in core.py

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 24, 2023

This deserves a mention in the release notes. See the directions in doc/release/upcoming_changes/README.rst

@mattip
Copy link
Copy Markdown
Member

mattip commented Mar 26, 2023

Let's give this a shot. Thanks @F3eQnxN3RriK

@mattip mattip merged commit ad09c69 into numpy:main Mar 26, 2023
@ghost ghost deleted the enh-ma-dot branch March 26, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants