scipy/scipy — comment on commit a31acbf966f50665997d1fd1ced41d3a8b3e4187
File:  line 0
By johannct:

this code seems to fix the occurrence of infinites. In the case of a nan returned value, the problem is different in the sense that the linesearch_wolfe1 internal loop within the "while 1" statement never exits. Looks like we need something like this patch :
diff --git a/scipy/optimize/linesearch.py b/scipy/optimize/linesearch.py
index 02e9375..f858744 100644
--- a/scipy/optimize/linesearch.py
+++ b/scipy/optimize/linesearch.py
@@ -145,7 +145,10 @@ def scalar_search_wolfe1(phi, derphi, phi0=None, old_phi0=None, derphi0=None,
stp, phi1, derphi1, task = minpack2.dcsrch(alpha1, phi1, derphi1,
c1, c2, xtol, task,
amin, amax, isave, dsave)
- if task[:2] == asbytes('FG'):
+ if np.isnan(phi1):
+ task[:5] == asbytes('ERROR')
+ break
+ if task[:2] == asbytes('FG'):
alpha1 = stp
phi1 = phi(stp)
derphi1 = derphi(stp)