[SciPy-Dev] incorrect function-call count in fsolve

Andrew Hawryluk HAWRYLA@novachem....
Tue Nov 23 17:49:07 CST 2010

I have just noticed that scipy.optimize.fsolve reports two fewer
function calls than actually occur. It returns the number of Fortran
function calls, but the Python code calls the function once to check the
dimensions and the C code calls the function again for error checking
(assuming I have understood the code correctly). The same thing is true
for calls to the Jacobian.

My two questions are:
Would it be appropriate for fsolve to return the number of Fortran calls
+ 2?
Would it be appropriate to provide an 'unsafe' option that bypasses
these calls? For some of my work I am calling fsolve several times
within other optimization/solver loops, so the Fortran code may only be
needing 1 Jacobian and 2 or 3 function calls much of the time. Bypassing
the additonal 2 Jacobians and function calls could speed things along a


from scipy.optimize import fsolve
import numpy as np

nfev = 0

def func(x):
    global nfev
    nfev += 1
    return np.cos(x)

solution = fsolve(func, 1.3, full_output=1)
print 'fsolve performed %d function calls' % solution[1]['nfev']
print 'but there were %d function calls in total' % nfev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20101123/b5e789cd/attachment.html 

More information about the SciPy-Dev mailing list