Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unitfulvalue for compatibility with ForwardDiff removal #2593

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ const TryAgain = SlowConvergence
DEFAULT_PRECS(W, du, u, p, t, newW, Plprev, Prprev, solverdata) = nothing, nothing
isdiscretecache(cache) = false

@static if isdefined(DiffEqBase, :unitfulvalue)
unitfulvalue(x) = DiffEqBase.unitfulvalue(x)
else
unitfulvalue(x) = DiffEqBase.ForwardDiff.value(x)
end

include("doc_utils.jl")
include("misc_utils.jl")

Expand Down
8 changes: 4 additions & 4 deletions lib/OrdinaryDiffEqCore/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ function DiffEqBase.__init(
abstol_internal = false
elseif abstol === nothing
if uBottomEltypeNoUnits == uBottomEltype
abstol_internal = DiffEqBase.ForwardDiff.value(real(convert(uBottomEltype,
abstol_internal = unitfulvalue(real(convert(uBottomEltype,
oneunit(uBottomEltype) *
1 // 10^6)))
else
abstol_internal = DiffEqBase.ForwardDiff.value.(real.(oneunit.(u) .* 1 // 10^6))
abstol_internal = unitfulvalue.(real.(oneunit.(u) .* 1 // 10^6))
end
else
abstol_internal = real.(abstol)
Expand All @@ -246,10 +246,10 @@ function DiffEqBase.__init(
reltol_internal = false
elseif reltol === nothing
if uBottomEltypeNoUnits == uBottomEltype
reltol_internal = DiffEqBase.ForwardDiff.value(real(convert(uBottomEltype,
reltol_internal = unitfulvalue(real(convert(uBottomEltype,
oneunit(uBottomEltype) * 1 // 10^3)))
else
reltol_internal = DiffEqBase.ForwardDiff.value.(real.(oneunit.(u) .* 1 // 10^3))
reltol_internal = unitfulvalue.(real.(oneunit.(u) .* 1 // 10^3))
end
else
reltol_internal = real.(reltol)
Expand Down
Loading