[SciPy-User] Gradient inputs to SciPy optimize routines

Nathaniel Smith njs at pobox.com
Tue Jul 24 10:00:54 EDT 2012


On Tue, Jul 24, 2012 at 2:21 AM, David Baddeley
<david_baddeley at yahoo.com.au> wrote:
> I would speculate that the reason the optimise routines don't accept
> arbitrary sequence types for the Jacobian is one of performance. The
> gradient functions get called many times during the optimisation and pythons
> sequence types are slow enough that converting the arbitrary sequence into
> an array would probably be slower than computing the Jacobian using finite
> differences within the algorithm. Although calling np.ascontiguous has
> relatively low overhead if the data is already an array, it is another
> function call (expensive in python) and could be up to ~30% of total running
> time for a simple model function. The same applies to too many checks on
> data type. Within the optimising loop, they will be costly.

The checks have to be done anyway (otherwise returning a non-array
would just cause a segfault), so there wouldn't be any slowdown for
accepting generic array_like's instead of just ndarrays here. I think
it's just a bug; someone should file a bug report/write a PR.

-n



More information about the SciPy-User mailing list