[Scipy-tickets] [SciPy] #377: fmin_bfgs incorrectly expects a ZeroDivisonError, fails if division by zero occurs

SciPy scipy-tickets@scipy....
Tue Feb 20 07:15:41 CST 2007


#377: fmin_bfgs incorrectly expects a ZeroDivisonError, fails if division by zero
occurs
----------------------------+-----------------------------------------------
 Reporter:  gdeanewsp       |       Owner:  somebody              
     Type:  defect          |      Status:  new                   
 Priority:  normal          |   Milestone:                        
Component:  scipy.optimize  |     Version:  0.5.2                 
 Severity:  normal          |    Keywords:  bfgs ZeroDivisionError
----------------------------+-----------------------------------------------
 optimize/optimize.py line 709-712:

 {{{
         try:
             rhok = 1 / (numpy.dot(yk,sk))
         except ZeroDivisionError:
             rhok = 1000.
             print "Divide-by-zero encountered: rhok assumed large"
 }}}

 This probably worked fine with Numeric, but now numpy.dot returns a
 1-element array
 and 1/array([0]) is [#INF] and does not raise an exception, consequently
 the optimization falls over if this condition is hit.

 Suggested fix:

 {{{
         try:
             rhok = 1.0 / float(numpy.dot(yk,sk))
         except ZeroDivisionError:
 }}}

 or replace try-except with a test for invalid value.

-- 
Ticket URL: <http://projects.scipy.org/scipy/scipy/ticket/377>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list