Not sure if I understand you correctly.
residualfn!
only modify du
in-place, so if du
is preallocated, it is easy to be retrieved from the cache and thus have a performance gain. But I am bit confused, if no parameter in the model is fixed, the problem is defined as prob = NonlinearLeastSquaresProblem(NonlinearFunction(lossfn!, resid_prototype = similar(ydata)), u0, data)
(as here, and du
is not preallocated but a performance gain is expected.
Here in my case, where some parameters of u
are transfered by closure:
prob = NonlinearLeastSquaresProblem(NonlinearFunction((dp, p, data) -> residual!(dp, [p; t₀], data), resid_prototype = similar(ys)), [y0, a, τ], (xs, ys))
I don’t get how I lose the performance gain.
Would you please demonstrate more? I would really appreciate that!