diff --git a/lib/SimpleNonlinearSolve/Project.toml b/lib/SimpleNonlinearSolve/Project.toml index ca2fe2c05..71f516462 100644 --- a/lib/SimpleNonlinearSolve/Project.toml +++ b/lib/SimpleNonlinearSolve/Project.toml @@ -1,38 +1,33 @@ name = "SimpleNonlinearSolve" uuid = "727e6d20-b764-4bd8-a329-72de5adea6c7" authors = ["SciML"] -version = "0.1.0" +version = "0.1.1" [deps] ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2" FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" -LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" -StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" -UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" +SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c" +StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" [compat] ArrayInterfaceCore = "0.1.1" FiniteDiff = "2" ForwardDiff = "0.10.3" -RecursiveArrayTools = "2" Reexport = "0.2, 1" SciMLBase = "1.73" -Setfield = "0.7, 0.8, 1" -StaticArrays = "0.12,1.0" -UnPack = "1.0" +SnoopPrecompile = "1" +StaticArraysCore = "1.4" julia = "1.6" [extras] BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" -ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff"] +test = ["BenchmarkTools", "SafeTestsets", "Pkg", "Test", "StaticArrays"] diff --git a/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl b/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl index 191bb8731..bd4788193 100644 --- a/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl +++ b/lib/SimpleNonlinearSolve/src/SimpleNonlinearSolve.jl @@ -1,13 +1,9 @@ module SimpleNonlinearSolve using Reexport -using UnPack: @unpack using FiniteDiff, ForwardDiff using ForwardDiff: Dual -using Setfield -using StaticArrays -using RecursiveArrayTools -using LinearAlgebra +using StaticArraysCore import ArrayInterfaceCore @reexport using SciMLBase @@ -23,6 +19,30 @@ include("falsi.jl") include("raphson.jl") include("ad.jl") +import SnoopPrecompile + +SnoopPrecompile.@precompile_all_calls begin for T in (Float32, Float64) + prob_no_brack = NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2)) + for alg in (SimpleNewtonRaphson,) + solve(prob_no_brack, alg(), tol = T(1e-2)) + end + + #= + for alg in (SimpleNewtonRaphson,) + for u0 in ([1., 1.], StaticArraysCore.SA[1.0, 1.0]) + u0 = T.(.1) + probN = NonlinearProblem{false}((u,p) -> u .* u .- p, u0, T(2)) + solve(probN, alg(), tol = T(1e-2)) + end + end + =# + + prob_brack = IntervalNonlinearProblem{false}((u, p) -> u * u - p, T.((0.0, 2.0)), T(2)) + for alg in (Bisection, Falsi) + solve(prob_brack, alg(), tol = T(1e-2)) + end +end end + # DiffEq styled algorithms export Bisection, Falsi, SimpleNewtonRaphson diff --git a/lib/SimpleNonlinearSolve/src/ad.jl b/lib/SimpleNonlinearSolve/src/ad.jl index 501324299..3b8d3fee0 100644 --- a/lib/SimpleNonlinearSolve/src/ad.jl +++ b/lib/SimpleNonlinearSolve/src/ad.jl @@ -28,14 +28,16 @@ function scalar_nlsolve_ad(prob, alg, args...; kwargs...) return sol, partials end -function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, SVector}, iip, +function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector}, + iip, <:Dual{T, V, P}}, alg::SimpleNewtonRaphson, args...; kwargs...) where {iip, T, V, P} sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...) return SciMLBase.build_solution(prob, alg, Dual{T, V, P}(sol.u, partials), sol.resid; retcode = sol.retcode) end -function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, SVector}, iip, +function SciMLBase.solve(prob::NonlinearProblem{<:Union{Number, StaticArraysCore.SVector}, + iip, <:AbstractArray{<:Dual{T, V, P}}}, alg::SimpleNewtonRaphson, args...; kwargs...) where {iip, T, V, P} sol, partials = scalar_nlsolve_ad(prob, alg, args...; kwargs...)