8000 ENH: Add ma.convolve and ma.correlate for #6458 by eric-wieser · Pull Request #7922 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add ma.convolve and ma.correlate for #6458 #7922

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

Merged
merged 4 commits into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
API: Rename contagious to propagate_mask
As discussed in the mailing list
  • Loading branch information
eric-wieser committed Oct 19, 2016
commit cb52fd63627fa7547f5467324726d151af3aff84
21 changes: 10 additions & 11 deletions numpy/ma/core.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -7366,8 +7366,8 @@ def outer(a, b):
outerproduct = outer


def _convolve_or_correlate(f, a, v, mode, contagious):
if contagious:
def _convolve_or_correlate(f, a, v, mode, propagate_mask):
if propagate_mask:
# results which are contributed to by either item in any pair being invalid
mask = (
f(getmaskarray(a), np.ones(v.shape, dtype=np.bool), mode=mode)
Expand All @@ -7382,7 +7382,7 @@ def _convolve_or_correlate(f, a, v, mode, contagious):
return masked_array(data, mask=mask)


def correlate(a, v, mode='valid', contagious=True):
def correlate(a, v, mode='valid', propagate_mask=True):
"""
Cross-correlation of two 1-dimensional sequences.

Expand All @@ -7393,10 +7393,9 @@ def correlate(a, v, mode='valid', contagious=True):
mode : {'valid', 'same', 'full'}, optional
Refer to the `np.convolve` docstring. Note that the default
is 'valid', unlike `convolve`, which uses 'full'.
contagious : bool
If True, then if any masked element is included in the sum for a result
element, then the result is masked.
If False, then the result element is only masked if no non-masked cells
propagate_mask : bool
If True, then a result element is masked if any masked element contributes towards it.
If False, then a result element is only masked if no non-masked element
contribute towards it

Returns
Expand All @@ -7408,10 +7407,10 @@ def correlate(a, v, mode='valid', contagious=True):
--------
numpy.correlate : Equivalent function in the top-level NumPy module.
"""
return _convolve_or_correlate(np.correlate, a, v, mode, contagious)
return _convolve_or_correlate(np.correlate, a, v, mode, propagate_mask)


def convolve(a, v, mode='full', contagious=True):
def convolve(a, v, mode='full', propagate_mask=True):
"""
Returns the discrete, linear convolution of two one-dimensional sequences.

Expand All @@ -7421,7 +7420,7 @@ def convolve(a, v, mode='full', contagious=True):
Input sequences.
mode : {'valid', 'same', 'full'}, optional
Refer to the `np.convolve` docstring.
contagious : bool
propagate_mask : bool
If True, then if any masked element is included in the sum for a result
element, then the result is masked.
If False, then the result element is only masked if no non-masked cells
Expand All @@ -7436,7 +7435,7 @@ def convolve(a, v, mode='full', contagious=True):
--------
numpy.convolve : Equivalent function in the top-level NumPy module.
"""
return _convolve_or_correlate(np.convolve, a, v, mode, contagious)
return _convolve_or_correlate(np.convolve, a, v, mode, propagate_mask)


def allequal(a, b, fill_value=True):
Expand Down
2 changes: 1 addition & 1 deletion numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4092,7 +4092,7 @@ def test_convolve(self):
test = np.ma.convolve(a, b)
assert_equal(test, masked_equal([0, 1, -1, -1, 7, 4], -1))

test = np.ma.convolve(a, b, contagious=False)
test = np.ma.convolve(a, b, propagate_mask=False)
assert_equal(test, masked_equal([0, 1, 1, 3, 7, 4], -1))


Expand Down
0