Skip to content

Commit

Permalink
Rename second_derivative -> secondderivative
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlero committed Jan 3, 2024
1 parent 94342de commit db8607c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/src/implementer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ They are just listed here to help readers figure out the code structure:
- `value_and_derivative` calls `value_and_jacobian`
- `value_and_gradient` calls `value_and_jacobian`
- `value_and_hessian` calls `jacobian` and `gradient`
- `value_and_second_derivative` calls `second_derivative`
- `value_and_second_derivative` calls `secondderivative`
- `value_gradient_and_hessian` calls `value_and_jacobian` and `gradient`
- `value_derivative_and_second_derivative` calls `value_and_derivative` and `second_derivative`
- `value_derivative_and_second_derivative` calls `value_and_derivative` and `secondderivative`
- `pushforward_function` calls `jacobian`
- `value_and_pushforward_function` calls `pushforward_function`
- `pullback_function` calls `value_and_pullback_function`
Expand Down
2 changes: 1 addition & 1 deletion docs/src/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The following list of functions can be used to request the derivative, gradient,
AbstractDifferentiation.derivative
AbstractDifferentiation.gradient
AbstractDifferentiation.jacobian
AbstractDifferentiation.second_derivative
AbstractDifferentiation.secondderivative
AbstractDifferentiation.hessian
```

Expand Down
16 changes: 8 additions & 8 deletions src/AbstractDifferentiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ function jacobian(ab::HigherOrderBackend, f, xs...)
end

"""
AD.second_derivative(ab::AD.AbstractBackend, f, xs...)
AD.secondderivative(ab::AD.AbstractBackend, f, xs...)
Compute the second derivative of `f` with respect to the input `x` using the backend `ab`.
The function returns a single value because `second_derivative` currently only supports a single input.
The function returns a single value because `secondderivative` currently only supports a single input.
"""
function second_derivative(ab::AbstractBackend, f, x)
function secondderivative(ab::AbstractBackend, f, x)
if x isa Tuple
# only support computation of second derivative for functions with single input argument
x = only(x)
Expand Down Expand Up @@ -162,10 +162,10 @@ end
Return the tuple `(v, d2)` of the function value `v = f(x)` and the second derivatives `d = AD.derivative(ab, f, x)` and `d2 = AD.hessian(ab, f, x)`.
See also [`AbstractDifferentiation.second_derivative`](@ref)
See also [`AbstractDifferentiation.secondderivative`](@ref)
"""
function value_and_second_derivative(ab::AbstractBackend, f, x)
return f(x), second_derivative(ab, f, x)
return f(x), secondderivative(ab, f, x)
end

"""
Expand Down Expand Up @@ -208,7 +208,7 @@ end
"""
AD.value_and_derivatives(ab::AD.AbstractBackend, f, x)
Return the tuple `(v, d, d2)` of the function value `v = f(x)` and the first and second derivatives `d = AD.derivative(ab, f, x)` and `d2 = AD.second_derivative(ab, f, x)`.
Return the tuple `(v, d, d2)` of the function value `v = f(x)` and the first and second derivatives `d = AD.derivative(ab, f, x)` and `d2 = AD.secondderivative(ab, f, x)`.
"""
function value_and_derivatives(ab::AbstractBackend, f, x)
if x isa Tuple
Expand All @@ -217,14 +217,14 @@ function value_and_derivatives(ab::AbstractBackend, f, x)
end

value = f(x)
deriv, second_deriv = value_and_derivative(
deriv, secondderiv = value_and_derivative(
second_lowest(ab), _x -> begin
d = derivative(lowest(ab), f, _x)
return d[1] # derivative returns a tuple
end, x
)

return value, (deriv,), second_deriv
return value, (deriv,), secondderiv
end

"""
Expand Down
6 changes: 3 additions & 3 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ function test_second_derivatives(backend; multiple_inputs=false, test_types=true
else
# explicit test that AbstractDifferentiation throws an error
# don't support tuple of second derivatives
@test_throws ArgumentError AD.second_derivative(
@test_throws ArgumentError AD.secondderivative(
backend, x -> fder(x, yscalar), (xscalar, yscalar)
)
@test_throws MethodError AD.second_derivative(
@test_throws MethodError AD.secondderivative(
backend, x -> fder(x, yscalar), xscalar, yscalar
)
end

# test if single input (no tuple works)
dder1 = AD.second_derivative(backend, x -> fder(x, yscalar), xscalar)
dder1 = AD.secondderivative(backend, x -> fder(x, yscalar), xscalar)
if test_types
@test dder1[1] isa Float64
end
Expand Down

0 comments on commit db8607c

Please sign in to comment.