Skip to content

Commit cbe4354

Browse files
authored
fix: PolyesterForwardDiff shouldn't be the default for static arrays (#495)
1 parent 810eeb3 commit cbe4354

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ PETSc = "0.3"
9898
Pkg = "1.10"
9999
PrecompileTools = "1.2"
100100
Preferences = "1.4"
101+
PolyesterForwardDiff = "0.1"
101102
Random = "1.10"
102103
ReTestItems = "1.24"
103104
Reexport = "1.2"
@@ -138,6 +139,7 @@ NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
138139
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
139140
PETSc = "ace2c81b-2b5f-4b1e-a30d-d662738edfe0"
140141
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
142+
PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b"
141143
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
142144
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
143145
SIAMFANLEquations = "084e46ad-d928-497d-ad5e-07fa361a48c4"
@@ -150,4 +152,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
150152
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
151153

152154
[targets]
153-
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enzyme", "ExplicitImports", "FastLevenbergMarquardt", "FixedPointAcceleration", "Hwloc", "InteractiveUtils", "LeastSquaresOptim", "LineSearches", "MINPACK", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEqTsit5", "PETSc", "Pkg", "Random", "ReTestItems", "SIAMFANLEquations", "SparseConnectivityTracer", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Test", "Zygote"]
155+
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enzyme", "ExplicitImports", "FastLevenbergMarquardt", "FixedPointAcceleration", "Hwloc", "InteractiveUtils", "LeastSquaresOptim", "LineSearches", "MINPACK", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEqTsit5", "PETSc", "Pkg", "PolyesterForwardDiff", "Random", "ReTestItems", "SIAMFANLEquations", "SparseConnectivityTracer", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Test", "Zygote"]

lib/NonlinearSolveBase/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NonlinearSolveBase"
22
uuid = "be0214bd-f91f-a760-ac4e-3421ce2b2da0"
33
authors = ["Avik Pal <avikpal@mit.edu> and contributors"]
4-
version = "1.3.0"
4+
version = "1.3.1"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

lib/NonlinearSolveBase/src/autodiff.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ function additional_incompatible_backend_check(prob::AbstractNonlinearProblem,
124124
end
125125
return hasbranching(prob.f, prob.u0, prob.p)
126126
end
127+
function additional_incompatible_backend_check(
128+
prob::AbstractNonlinearProblem, ::ADTypes.AutoPolyesterForwardDiff)
129+
prob.u0 isa SArray && return true # promotes to a mutable array
130+
return false
131+
end
127132

128133
is_finite_differences_backend(ad::AbstractADType) = false
129134
is_finite_differences_backend(::ADTypes.AutoFiniteDiff) = true

test/core_tests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,16 @@ end
414414
solve(prob)
415415
@test sol.u[1.0, 0.25] atol=1e-3 rtol=1e-3
416416
end
417+
418+
@testitem "No PolyesterForwardDiff for SArray" tags=[:core] begin
419+
using StaticArrays, PolyesterForwardDiff
420+
421+
f_oop(u, p) = u .* u .- p
422+
423+
N = 4
424+
u0 = SVector{N, Float64}(ones(N) .+ randn(N) * 0.01)
425+
426+
nlprob = NonlinearProblem(f_oop, u0, 2.0)
427+
428+
@test !(solve(nlprob, NewtonRaphson()).alg.autodiff isa AutoPolyesterForwardDiff)
429+
end

0 commit comments

Comments
 (0)