Skip to content
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

BUG: Avoid inplace modification of input array in newton #9991

Merged
merged 2 commits into from
Mar 30, 2019

Conversation

Kai-Striega
Copy link
Member

optimize.newton previously changes the users input array when
performing calculations. This PR changes this to perform an explicit
copy of the array before any inplace modifications are performed.

closes #9964.

optimize.newton previously changes the users input array when
performing calculations. This PR changes this to perform an explicit
copy of the array before any inplace modifications are performed.
@rgommers rgommers added scipy.optimize maintenance Items related to regular maintenance tasks labels Mar 29, 2019
@rgommers
Copy link
Member

Hmm, that looks like a recent regression, hard to believe that newton always did that.

@rgommers
Copy link
Member

there's a minor style issue that caused CI to fail

@Kai-Striega
Copy link
Member Author

@rgommers fixed the codestyle issue. Looking at the git history, it seems to have been around for a while.

(sp-dev) kai@t470:~/Develop/scipy$ git blame -L 362,366 HEAD~2 scipy/optimize/zeros.py
e1d50a7b7e (Mark Mikofski 2018-06-24 18:21:29 -0700 362)     try:
e1d50a7b7e (Mark Mikofski 2018-06-24 18:21:29 -0700 363)         p = np.asarray(x0, dtype=float)
998a458dd8 (Ralf Gommers  2018-06-24 23:34:28 -0700 364)     except TypeError:
998a458dd8 (Ralf Gommers  2018-06-24 23:34:28 -0700 365)         # can't convert complex to float
e1d50a7b7e (Mark Mikofski 2018-06-24 18:21:29 -0700 366)         p = np.asarray(x0)

@rgommers
Copy link
Member

Looking at the git history, it seems to have been around for a while.

Well, those commits went into 1.2.0, so it's a regression in the latest release because of gh-8357.

@rgommers rgommers added this to the 1.3.0 milestone Mar 30, 2019
@rgommers rgommers added the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Mar 30, 2019
@rgommers rgommers merged commit 1e53bef into scipy:master Mar 30, 2019
@rgommers
Copy link
Member

Merged, thanks @Kai-Striega

@rgommers
Copy link
Member

@mikofski FYI in case you didn't see it

@Kai-Striega Kai-Striega deleted the array_copy_9964 branch March 30, 2019 06:57
@tylerjereddy
Copy link
Contributor

This is in the 1.3.x maintenance branch already too--presumably backport label is for 1.2.x LTS. I think that gels with the discussion above.

@tylerjereddy tylerjereddy removed the backport-candidate This fix should be ported by a maintainer to previous SciPy versions. label Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

optimize.newton : overwrites x0 argument when it is a numpy array
3 participants