Skip to content

BUG: optimize.root_scalar: let bracket be passed as a NumPy array #21116

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 1 commit into from
Jul 11, 2024

Conversation

tartopohm
Copy link
Contributor

What does this implement/fix?

The method used by root_scalar depends on the optional arguments passed to the function. Whether bracket is passed is tested by evaluating its truthiness. That raises a ValueError if bracket is passed as a numpy array:
ValueError: The truth value of an array with more than one element is ambiguous.

This commit fixes this by testing bracket against None, and adds a simple test to check that the root obtained when passing bracket as an array is correct.

Additional information

A check was already in place within root_scalar to verify bracket is a list, tuple, or np.ndarray, which led me to believe passing the parameter as a np.ndarray should be accepted by this function.

The method used by `root_scalar` depends on the optional arguments
passed to the function. Whether `bracket` is passed is tested by
evaluating its truthiness. That raises a `ValueError` if `bracket` is
passed as a numpy array.
This commit fixes this by testing `bracket` against `None`.
@tartopohm tartopohm requested a review from andyfaff as a code owner July 5, 2024 09:36
@github-actions github-actions bot added scipy.optimize defect A clear bug or issue that prevents SciPy from being installed or used as expected labels Jul 5, 2024
@lucascolley
Copy link
Member

this looks correct to me, although I'm not sure whether the documented type "sequence" has a more precise meaning historically.

@lucascolley lucascolley changed the title BUG: optimize.root_scalar: let bracket be passed as a numpy array BUG: optimize.root_scalar: let bracket be passed as a NumPy array Jul 6, 2024
@dschmitz89
Copy link
Contributor

Thanks @tartopohm .

@dschmitz89 dschmitz89 merged commit 5247bd4 into scipy:main Jul 11, 2024
37 of 38 checks passed
@lucascolley lucascolley added this to the 1.15.0 milestone Jul 11, 2024
@tartopohm tartopohm deleted the root_scalar_bracket branch July 12, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants