[SciPy-User] Weird error in fmin_l_bfgs_b

Skipper Seabold jsseabold at gmail.com
Fri Jul 1 18:08:31 EDT 2011


On Fri, Jul 1, 2011 at 6:36 AM, Jose Gomez-Dans <jgomezdans at gmail.com> wrote:
> Hi,
> I'm getting an error in scipy.optimize.fmin_l_bfgs_b, apparently related to
> the fortran wrapper. This is strange, because exactly the same problem works
> well with the TNC solver. I have a function that returns both a scalar value
> (that will be minimised) and the derivative of the function at that point.
> The error in the L-BFG-S solver is
> File "/usr/lib/python2.7/dist-packages/scipy/optimize/lbfgsb.py", line 181,
> in fmin_l_bfgs_b
>     isave, dsave)
> ValueError: failed to initialize intent(inout) array -- input not fortran
> contiguous
>
>
> My code looks like this:
>
> # x0 is the starting point, a 1d array
>>>> solution, x, info = scipy.optimize.fmin_tnc( cost_function, x0,
>>>> args=([operators]),  bounds=bounds )
> # Using fmin_tnc works well, solution is what I expect it to be
>
>>> solution, cost, information = scipy.optimize.fmin_l_bfgs_b (
>>> cost_function, solution, bounds=bounds,  args=[ operators ], iprint=101 )

I've run into this before, though rarely. Is solution from TNC Fortran
contiguous? It's written in C though I don't know if it matters. IIUC,
it's the only thing that's intent inout and an array.

solution.flags

If this is indeed the problem, is this something that can be
automatically fixed in the python code of fmin_l_bfgs_b beforehand at
the expense of a copy?

Skipper



More information about the SciPy-User mailing list