Skip to content

Commit

Permalink
Remove the jacobian and primal_value primitives (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Sep 19, 2023
1 parent 8adb20e commit b307fea
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ext/AbstractDifferentiationFiniteDifferencesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Create an AD backend that uses forward mode with FiniteDifferences.jl.
"""
AD.FiniteDifferencesBackend() = AD.FiniteDifferencesBackend(FiniteDifferences.central_fdm(5, 1))

AD.@primitive function jacobian(ba::AD.FiniteDifferencesBackend, f, xs...)
function AD.jacobian(ba::AD.FiniteDifferencesBackend, f, xs...)
return FiniteDifferences.jacobian(ba.method, f, xs...)
end

Expand Down
2 changes: 1 addition & 1 deletion ext/AbstractDifferentiationReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ AD.primal_value(x::ReverseDiff.TrackedReal) = ReverseDiff.value(x)
AD.primal_value(x::AbstractArray{<:ReverseDiff.TrackedReal}) = ReverseDiff.value.(x)
AD.primal_value(x::ReverseDiff.TrackedArray) = ReverseDiff.value(x)

AD.@primitive function jacobian(ba::AD.ReverseDiffBackend, f, xs...)
function AD.jacobian(ba::AD.ReverseDiffBackend, f, xs...)
xs_arr = map(AD.asarray, xs)
tape = ReverseDiff.JacobianTape(xs_arr) do (xs_arr...)
xs_new = map(xs, xs_arr) do x, x_arr
Expand Down
14 changes: 0 additions & 14 deletions src/AbstractDifferentiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ macro primitive(expr)
return define_pushforward_function_and_friends(fdef) |> esc
elseif name == :pullback_function
return define_pullback_function_and_friends(fdef) |> esc
elseif name == :jacobian
return define_jacobian_and_friends(fdef) |> esc
elseif name == :primal_value
return define_primal_value(fdef) |> esc
else
throw("Unsupported AD primitive.")
end
Expand Down Expand Up @@ -574,16 +570,6 @@ end
_eachcol(a::Number) = (a,)
_eachcol(a) = eachcol(a)

function define_jacobian_and_friends(fdef)
fdef[:name] = :($(AbstractDifferentiation).jacobian)
return ExprTools.combinedef(fdef)
end

function define_primal_value(fdef)
fdef[:name] = :($(AbstractDifferentiation).primal_value)
return ExprTools.combinedef(fdef)
end

function identity_matrix_like(x)
throw("The function `identity_matrix_like` is not defined for the type $(typeof(x)).")
end
Expand Down
4 changes: 2 additions & 2 deletions test/defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
FDMBackend1() = FDMBackend1(central_fdm(5, 1))
const fdm_backend1 = FDMBackend1()
# Minimal interface
AD.@primitive function jacobian(ab::FDMBackend1, f, xs...)
function AD.jacobian(ab::FDMBackend1, f, xs...)
return FDM.jacobian(ab.alg, f, xs...)
end

Expand Down Expand Up @@ -49,7 +49,7 @@ end
## ForwardDiff
struct ForwardDiffBackend1 <: AD.AbstractForwardMode end
const forwarddiff_backend1 = ForwardDiffBackend1()
AD.@primitive function jacobian(ab::ForwardDiffBackend1, f, xs)
function AD.jacobian(ab::ForwardDiffBackend1, f, xs)
if xs isa Number
return (ForwardDiff.derivative(f, xs),)
elseif xs isa AbstractArray
Expand Down

0 comments on commit b307fea

Please sign in to comment.