[SciPy-User] leastsq and cython

Till Stensitzki mail.till@gmx...
Sat Sep 25 17:45:20 CDT 2010

Warren Weckesser <warren.weckesser <at> enthought.com> writes:

>     On 9/25/10 4:27 PM, Charles R Harris wrote:
>       On Sat, Sep 25, 2010 at 3:03 PM, David Baddeley <david_baddeley <at> 
>         wrote:
>           I've,  run into a similar problem, it's due to the fact that
>           native methods (ie
>           ones loaded from c libraries) are not quite the same as pure
>           python function
>           objects & don't possess all the nice attributes. It's been
>           a while, but I seem
>           to remember that this error crops up when leastsq is trying to
>           print some form
>           of status message with the function name in it. I've
>           circumvented the problem by
>           making a thin python wrapper function which just calls my c
>           method. This works,
>           but is not ideal, as you introduce additional function call
>           overhead. If anyone
>           out there knows of a better solution I'd also be interested.
>           Maybe it shouldn't try to print the function name? The context
>           of the message might be enough.
>     The function 'check_func' in minpack.py uses the attribute
>     'func_name' in an error message.  I'm tweaking 'check_func' now so
>     that it first checks for the 'func_name' attribute before trying to
>     use it.
>     Any suggestions for incorporating a cython or ctypes function into a
>     test, so I can include tests of the change?
>     Warren
> _______________________________________________
> SciPy-User mailing list
> SciPy-User <at> scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

Hmm, i tried to change my check_func too, but it seems the error stems also from 
c/fortran code. While cython function don't have the func_name attribute, the 
have the __name__  attribute, maybe it help. While we are at it, i have some 
questions about leastsq:

1. it seems to use always the double precision versions of lmdif, is there a way 
to change it? I am using cuda for the calculation of my function values, so no 
double precision for me. Another reason for using the single precision are 
memory concerns, as i am fitting around 70 000 data points with 600 parameters, 
so the size of jacobian is quite big.

2. does it use the same blas/lapack liberays as numpy?

3. does it copy the Jacobian every time, or is there a way to write directly to 
the right memory?

thanks for the fast answers and help,

More information about the SciPy-User mailing list