[SciPy-dev] Removing globals from minpack wrapper

Yosef Meller mellerf@netvision.net...
Wed Jun 25 11:06:27 CDT 2008


I was having my fun with optimize.fsolve() at work, when I realized that 
both the Python side and the C/FORTRAN side allocate work spaces, and 
then copy between them, which seemed wasteful. I started playing around 
with the code to try and create a version that allows the same buffer to 
move around between Python and minpack.

I couldn't do that (and I doubt now that it's possible), but on the way 
I found a method to remove the global variables that are used to store 
the data needed by the multipack functions but not passed in by the 
FORTRAN code which doesn't even know about it.

The trick was to allocate extra space on the work buffers and use it as 
a pointer to a structure that contains the information. This may seem 
just as ugly, but it has all the advantages of not using globals, 
including the prospects of someday making it thread-safe.

The attached patch implements the trick in minpack_hybrj, and the Python 
code tests that it works.

Do you think it's worth doing to the rest of the minpack functions?

-- 
http://yosefm.imagekind.com/Eclectic
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nuke_globals.patch
Type: text/x-diff
Size: 6132 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-dev/attachments/20080625/6f13e577/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_globals_nuke.py
Type: text/x-python
Size: 284 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/scipy-dev/attachments/20080625/6f13e577/attachment.py 


More information about the Scipy-dev mailing list