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

Expose dual tag to user #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

abstract type AbstractDiffMethod end

struct ForwardAD <: AbstractDiffMethod end
struct ForwardAD <: AbstractDiffMethod
dualtag::Union{Nothing, Missing} # tag for dual numbers (missing=automatic)
ForwardAD(; dualtag=missing) = new(dualtag)
end

struct ReverseAD <: AbstractDiffMethod end
# struct RevZyg <: AbstractDiffMethod end # only used for gradients (not jacobians)
struct ForwardFD <: AbstractDiffMethod end
Expand Down Expand Up @@ -186,9 +190,11 @@ function createcache(sp::DensePattern, dtype::ForwardAD, func!, nx, ng)
fg[1] = func!(@view(fg[2:end]), x)
end

tag = ismissing(dtype.dualtag) ? combine! : dtype.dualtag

g = zeros(1 + ng)
x = zeros(nx)
config = ForwardDiff.JacobianConfig(combine!, g, x)
config = ForwardDiff.JacobianConfig(tag, g, x)
J = DiffResults.JacobianResult(g, x)

return DenseCache(combine!, g, J, config, dtype)
Expand Down