-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
BUG: integrate.trapezoid: fix broadcasting issue #21912
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
Conversation
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.
thanks for the fix Andrew! Just need to make the new test generic over namespaces, along the lines of the suggestions I've added.
integrate.trapezoid
fixCo-authored-by: Lucas Colley <[email protected]>
assert_allclose(trapezoid(y, x=np.array([0, 10., 20.]), axis=0), out0) | ||
# x needs to be broadcastable against y | ||
assert_allclose( | ||
trapezoid(y, x=np.array([0, 10., 20.])[:, None], axis=0), | ||
out0 | ||
) | ||
with pytest.raises(Exception): | ||
# x is not broadcastable against y | ||
trapezoid(y, x=np.array([0, 10., 20.])[None, :], axis=0) | ||
|
||
out1 = np.array([ 40.5, 130.5, 220.5]) | ||
assert_allclose(trapezoid(y, x=x, axis=1), out1) | ||
assert_allclose( | ||
trapezoid(y, x=np.array(np.linspace(0, 9, 10)), axis=1), | ||
out1 | ||
) |
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.
in case I wasn't clear, the rest of the test needs changes too (np
-> xp
, assert_allclose
-> xp_assert_close
)
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, thanks!
Closes #21908.
Fixes the 1-D case, and fixes another problem with the n-D case that wasn't picked up by our tests. The latter problem was that it wasn't possible to integrate with an
x
array that had exactly the same shape asy
.The only selection rule for
x
is that it needs to be broadcastable toy
along the axis of integration.