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

Remove the jacobian and primal_value primitives #95

Merged
merged 1 commit into from
Sep 19, 2023
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
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