Re: optimize.least_squares memory allocation every function call

Dominik StaƄczak <[email protected]> Tue, 14 Apr 2020 11:01:12 +0200
Newsgroups gmane.comp.python.scientific.user
Message-ID <CALqoO-5cVF02rVrhi+_GJtzzD9hyn0hZjb_1y+iangTOQu-i=g@mail.gmail.com>
Hey Brian,

I haven't tested this, but, off the top of my head: would it not be
possible to pass a pre-existing allocated array as a `kwarg` to the
function, and have your function write values into that array? Then you can
add it to the `least_squares` call as `{"return_array": np.zeros(N)}).

Cheers,
Dominik

On Tue, 14 Apr 2020 at 10:40, Brian Hare <[email protected]> wrote:

> I have a question about the scipy.optimize.least_squares function.  I have
> found that the function to optimize needs to reallocate the return array
> every time the function is called. I've tried having the calling function
> return the same array every time (just re-filled with the correct return
> values), but least_squares doesn't seem to converge when I do this.
>
> I do not like having to allocate memory in the calling function, this
> seems slow and unnecessary. Is there a way around this? If not, could scipy.optimize.least_squares
> be adjusted so this is possible?
>
> The Gnu Scientific Library (which I sometimes fall back on when scipy.optimize.least_squares
> is too slow, I think this allocation issue is one major contributor),
> passes an array to the calling function to fill.
>
> Thank you,
> Brian Hare
> _______________________________________________
> SciPy-User mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/scipy-user
>

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user