Skip to content

Commit e14d7dd

Browse files
committed
test overwrite
1 parent c754512 commit e14d7dd

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

.buildkite/Manifest-v1.11.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,8 +2540,8 @@ version = "1.0.2"
25402540

25412541
[[deps.Thermodynamics]]
25422542
deps = ["DocStringExtensions", "ForwardDiff", "KernelAbstractions", "Random", "RootSolvers"]
2543-
git-tree-sha1 = "1a0e57d536d10f5bf3c7d0ab8e672321f2f89778"
2544-
repo-rev = "zs/test_derivatives"
2543+
git-tree-sha1 = "1c6b10882d535f28b5c79be9d8d782a12f5592f9"
2544+
repo-rev = "zs/test_autodiff"
25452545
repo-url = "https://github.com/CliMA/Thermodynamics.jl.git"
25462546
uuid = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
25472547
version = "0.12.15"

src/prognostic_equations/implicit/autodiff_utils.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@ end
143143
return ForwardDiff.dual_definition_retval(tag, val, deriv, partials)
144144
end
145145

146+
# Set the derivative of max(x, y) to handle cases where x == y. When x == y,
147+
# the derivative is set to the derivative of x (the first argument) to ensure
148+
# continuity and avoid numerical issues. This is a common approach in automatic
149+
# differentiation for max functions.
150+
151+
@inline function Base.max(d::ForwardDiff.Dual{Jacobian}, r::Integer)
152+
tag = Val(Jacobian)
153+
x = ForwardDiff.value(d)
154+
partials = ForwardDiff.partials(d)
155+
val = max(x, r)
156+
deriv = 1
157+
return ForwardDiff.dual_definition_retval(tag, val, deriv, partials)
158+
end
159+
160+
# @inline function Base.clamp(d::ForwardDiff.Dual{Jacobian}, r1::FT, r2::FT) where {FT}
161+
# tag = Val(Jacobian)
162+
# x = ForwardDiff.value(d)
163+
# partials = ForwardDiff.partials(d)
164+
# val = clamp(x, r1, r2)
165+
# deriv = 1
166+
# return ForwardDiff.dual_definition_retval(tag, val, deriv, partials)
167+
# end
168+
146169
# Ignore all derivative information when comparing Duals to other Numbers. This
147170
# ensures that conditional statements are always equivalent for Duals and Reals.
148171
for func in (:iszero,)

0 commit comments

Comments
 (0)