Forward-mode is correct, and 1.11 onwards is correct. Enzyme@0.13.129
import Enzyme
function wlj(x::Real, lower::Bool, upper::Real)
lbounded, ubounded = lower, isfinite(upper)
return if lbounded && ubounded
(log(x/upper) / one(x)), 0.0
elseif lbounded
log(x), 0.0
elseif ubounded
log(x), 0.0
else
x, 0.0
end
end
struct Foo
upper::Float64
end
function (f::Foo)(rx::AbstractArray)
return [first(wlj(rx[], true, f.upper))]
end
x = [0.5]
f = Foo(1.0)
Enzyme.jacobian(Enzyme.Reverse, f, x) # [0.0;;]
import ForwardDiff
@show ForwardDiff.jacobian(f, x) # [2.0;;]
versioninfo
julia> versioninfo()
Julia Version 1.10.10
Commit 95f30e51f41 (2025-06-27 09:51 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: macOS (arm64-apple-darwin24.0.0)
CPU: 10 × Apple M1 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Forward-mode is correct, and 1.11 onwards is correct. Enzyme@0.13.129
versioninfo