[SciPy-Dev] ENH: WIP: Cython optimize · Issue #8431 · scipy/scipy

Mark Alexander Mikofski mikofski at berkeley.edu
Sun Apr 8 04:48:32 EDT 2018


I've started work on a cython_optimize.zeros package to address the need
for fast looping of scalar zero methods over arrays, see issues 8354 and
7242.

https://github.com/scipy/scipy/pull/8431

This PR is still a work in progress. I wanted to get feedback on the API(s)
that would be most useful. I don't think there should be too many versions
but it should be something widely acceptible. Sorry if my proposals are a
bit premature or insufficiently developed, but I wanted to start the
discussion. Here are some ideas to start with:

Option 1:
ctypedef double (*callback_type_tup)(double, tuple)

- takes a double and a Python tuple with extra arguments, this is the only
interface implemented so far, and only for bisect and a super-lite version
of newton, it is modeled after the existing Python C-API methods in zeros.c
for bisect and other solvers, see description in cython_optimize/__init__.py


Option 2:
ctypedef double (*callback_type_struct)(double, void*)

- takes a double and a structure that contains a structure with the extra
arguments, uses a wrapper to extract the extra arguments and call the
function

Option 3:
ctypedef double (*callback_type)(double, void*)

- takes a double and a structure that contains the extra arguments, this
implementation does not have a wrapper function to extract the args and
call the function

Option 4:
ctypedef double (*callback_type_array)(double, void*)

- takes a double and a structure that contains an array with the extra
arguments, this method uses a wrapper to extract the extra arguments and
call the function

I guess I'm leaning toward either option 2 or 3, but perhaps there are
other API(s) that are more desirable? Also there are other questions that
this PR raises like: is it okay to split up Newton, Halley, and secant? And
is it okay to *not* return a `RootsResult` object from the Ridder, Brent,
and bisect methods, or should the API(s) match their Python equivalents?
Should there be a numpy cython API for super fast looping with native numpy
arrays (or other array type like what?)

Also note there is a parallel effort in PR 8357 which uses numpy but only
with scipy.optimize.zeros.newton. IMHO both of these efforts are desirable
and do not compete against each other.

Thanks for your feedback!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180408/ea2451c4/attachment.html>


More information about the SciPy-Dev mailing list