Skip to content

Commit

Permalink
Merge pull request #8248 from dlax/optimize/fix-name-error-in-ncg
Browse files Browse the repository at this point in the history
BUG: declare "gfk" variable before call of terminate() in newton-cg
  • Loading branch information
pv committed Dec 22, 2017
2 parents ce36940 + be7496a commit 723e0a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions scipy/optimize/optimize.py
Expand Up @@ -1557,6 +1557,7 @@ def terminate(warnflag, msg):
if retall:
allvecs = [xk]
k = 0
gfk = None
old_fval = f(x0)
old_old_fval = None
float64eps = numpy.finfo(numpy.float64).eps
Expand Down
8 changes: 8 additions & 0 deletions scipy/optimize/tests/test_optimize.py
Expand Up @@ -321,6 +321,14 @@ def test_neldermead_initial_simplex_bad(self):
full_output=True, disp=False, retall=False,
initial_simplex=simplex)

def test_ncg_negative_maxiter(self):
# Regression test for gh-8241
opts = {'maxiter': -1}
result = optimize.minimize(self.func, self.startparams,
method='Newton-CG', jac=self.grad,
args=(), options=opts)
assert_(result.status == 1)

def test_ncg(self):
# line-search Newton conjugate gradient optimization routine
if self.use_wrapper:
Expand Down

0 comments on commit 723e0a3

Please sign in to comment.