Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: Fix calling ufuncs with a positional output argument.#10560

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
charris merged 1 commit intonumpy:maintenance/1.14.xfromcharris:backport-10479
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
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
BUG: Fix calling ufuncs with a positional output argument.
Currently, this causes the result to inherit the output's mask.This brings `np.add(a, b, out)` in line with  `np.add(a, b, out=out)`.These previously differed becausegh-10459 causes them to call__array_wrap__ in different ways (with and without the output argumentin the context tuple, respectively).Since the data in the `out` argument is never used by ufuncs, it seemsconsistent that the mask should not be either.
  • Loading branch information
@eric-wieser@charris
eric-wieser authored andcharris committedFeb 9, 2018
commit2a5eac2bcbfab59f18fb2bdccea71a1fe7f58dbd
12 changes: 7 additions & 5 deletionsnumpy/ma/core.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3010,18 +3010,20 @@ def __array_wrap__(self, obj, context=None):

if context is not None:
result._mask = result._mask.copy()
(func, args, _) = context
m = reduce(mask_or, [getmaskarray(arg) for arg in args])
func, args, out_i = context
# args sometimes contains outputs (gh-10459), which we don't want
input_args = args[:func.nin]
m = reduce(mask_or, [getmaskarray(arg) for arg in input_args])
# Get the domain mask
domain = ufunc_domain.get(func, None)
if domain is not None:
# Take the domain, and make sure it's a ndarray
if len(args) > 2:
if len(input_args) > 2:
with np.errstate(divide='ignore', invalid='ignore'):
d = filled(reduce(domain,args), True)
d = filled(reduce(domain,input_args), True)
else:
with np.errstate(divide='ignore', invalid='ignore'):
d = filled(domain(*args), True)
d = filled(domain(*input_args), True)

if d.any():
# Fill the result where the domain is wrong
Expand Down
26 changes: 26 additions & 0 deletionsnumpy/ma/tests/test_core.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5052,6 +5052,32 @@ def test_ufunc_with_output():
y = np.add(x, 1., out=x)
assert_(y is x)


def test_ufunc_with_out_varied():
""" Test that masked arrays are immune to gh-10459 """
# the mask of the output should not affect the result, however it is passed
a = array([ 1, 2, 3], mask=[1, 0, 0])
b = array([10, 20, 30], mask=[1, 0, 0])
out = array([ 0, 0, 0], mask=[0, 0, 1])
expected = array([11, 22, 33], mask=[1, 0, 0])

out_pos = out.copy()
res_pos = np.add(a, b, out_pos)

out_kw = out.copy()
res_kw = np.add(a, b, out=out_kw)

out_tup = out.copy()
res_tup = np.add(a, b, out=(out_tup,))

assert_equal(res_kw.mask, expected.mask)
assert_equal(res_kw.data, expected.data)
assert_equal(res_tup.mask, expected.mask)
assert_equal(res_tup.data, expected.data)
assert_equal(res_pos.mask, expected.mask)
assert_equal(res_pos.data, expected.data)


def test_astype():
descr = [('v', int, 3), ('x', [('y', float)])]
x = array(([1, 2, 3], (1.0,)), dtype=descr)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp