Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 98e6af3

Browse files
committed
Add AllocCheck.jl
1 parent 51b3608 commit 98e6af3

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
23
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
34
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
45
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

test/basictests.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using BenchmarkTools, LinearSolve, SimpleNonlinearSolve, StaticArrays, Random,
1+
using AllocCheck, BenchmarkTools, LinearSolve, SimpleNonlinearSolve, StaticArrays, Random,
22
LinearAlgebra, Test, ForwardDiff, DiffEqBase
33

44
_nameof(x) = applicable(nameof, x) ? nameof(x) : _nameof(typeof(x))
@@ -255,6 +255,39 @@ end
255255
end
256256
end
257257

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+
258291
# --- Interval Nonlinear Problems ---
259292

260293
@testset "Interval Nonlinear Problem: $(alg)" for alg in (Bisection(), Falsi(), Ridder(),

0 commit comments

Comments
 (0)