|
1 | | -using BenchmarkTools, LinearSolve, SimpleNonlinearSolve, StaticArrays, Random, |
| 1 | +using AllocCheck, BenchmarkTools, LinearSolve, SimpleNonlinearSolve, StaticArrays, Random, |
2 | 2 | LinearAlgebra, Test, ForwardDiff, DiffEqBase |
3 | 3 |
|
4 | 4 | _nameof(x) = applicable(nameof, x) ? nameof(x) : _nameof(typeof(x)) |
|
255 | 255 | end |
256 | 256 | end |
257 | 257 |
|
| 258 | +# --- Allocation Checks --- |
| 259 | + |
| 260 | +## SimpleDFSane needs to allocate a history vector |
| 261 | +@testset "Allocation Checks: $(_nameof(alg))" for alg in ( |
| 262 | + SimpleNewtonRaphson(; autodiff = AutoForwardDiff(; chunksize = 2)), |
| 263 | + SimpleHalley(; autodiff = AutoForwardDiff(; chunksize = 2)), |
| 264 | + SimpleBroyden(), SimpleKlement(), SimpleLimitedMemoryBroyden(), |
| 265 | + SimpleTrustRegion(; autodiff = AutoForwardDiff(; chunksize = 2))) |
| 266 | + @check_allocs nlsolve(prob, alg) = DiffEqBase.__solve(prob, alg; abstol = 1e-9) |
| 267 | + |
| 268 | + nlprob_scalar = NonlinearProblem{false}(quadratic_f, 1.0, 2.0) |
| 269 | + nlprob_sa = NonlinearProblem{false}(quadratic_f, @SVector[1.0, 1.0], 2.0) |
| 270 | + |
| 271 | + try |
| 272 | + nlsolve(nlprob_scalar, alg) |
| 273 | + @test true |
| 274 | + catch e |
| 275 | + @error e |
| 276 | + @test false |
| 277 | + end |
| 278 | + |
| 279 | + # ForwardDiff allocates for hessian since we don't propagate the chunksize |
| 280 | + # SimpleLimitedMemoryBroyden needs to do views on the low rank matrices so the sizes |
| 281 | + # are dynamic. This can be fixed but no without maintaining the simplicity of the code |
| 282 | + try |
| 283 | + nlsolve(nlprob_sa, alg) |
| 284 | + @test true |
| 285 | + catch e |
| 286 | + @error e |
| 287 | + @test false broken=(alg isa SimpleHalley || alg isa SimpleLimitedMemoryBroyden) |
| 288 | + end |
| 289 | +end |
| 290 | + |
258 | 291 | # --- Interval Nonlinear Problems --- |
259 | 292 |
|
260 | 293 | @testset "Interval Nonlinear Problem: $(alg)" for alg in (Bisection(), Falsi(), Ridder(), |
|
0 commit comments