I am in the process of migrating some code from NLsolve.jl to NonlinearSolve.jl. I have written a simple Newton-Raphson test, but I cannot get the allocations down to zero; both solve! and reinit! allocate. Can this be improved?
using NonlinearSolve
N = 1000
u0 = rand(N)
f!(J, u, p) = @. J = (u - 1)
problem = NonlinearProblem{true}(f!, u0)
solver = NewtonRaphson(
autodiff = AutoForwardDiff(;
chunksize = NonlinearSolve.pickchunksize(problem.u0),
),
)
cache = init(problem, solver)
solve!(cache)
reinit!(cache)
println(@allocated solve!(cache))
println(@allocated reinit!(cache))
The caching API minimizes allocations but doesnât make them go down to zero. The allocations in the above code would come from LU factorization IIRC.