Skip to content

Commit

Permalink
Merge pull request #19 from fzimmermann89/returnifmaxiter
Browse files Browse the repository at this point in the history
Return result with warning if maximum number of iterations is reached
  • Loading branch information
fgregg authored Dec 18, 2021
2 parents a782de0 + ac95975 commit 1652a18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lbfgs/_lowlevel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ cdef class LBFGS(object):
<void *>x_a).copy()

return x_array.reshape(x0.shape)
elif r in (LBFGSERR_ROUNDING_ERROR, LBFGSERR_MAXIMUMLINESEARCH) :
elif r in (LBFGSERR_ROUNDING_ERROR, LBFGSERR_MAXIMUMLINESEARCH, LBFGSERR_MAXIMUMITERATION) :
warnings.warn(_ERROR_MESSAGES[r])
x_array = np.PyArray_SimpleNewFromData(1, tshape, np.NPY_DOUBLE,
<void *>x_a).copy()
Expand Down
6 changes: 5 additions & 1 deletion tests/test_lbfgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ def f(x, g, *args):
opt.max_iterations = 3

assert_array_equal(opt.minimize(f, 1e6), [0])

opt.max_iterations = 1
with pytest.warns(UserWarning):
opt.minimize(f, 1e7)

opt.ftol = -1
with pytest.raises(LBFGSError):
opt.minimize(f, 1e7)

Expand Down

0 comments on commit 1652a18

Please sign in to comment.