Skip to content

Commit

Permalink
add old ctderivative
Browse files Browse the repository at this point in the history
  • Loading branch information
ocots committed Jun 22, 2024
1 parent 6abea2b commit 6f49f3f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CTBase"
uuid = "54762871-cc72-4466-b8e8-f6c8b58076cd"
authors = ["Olivier Cots <[email protected]>"]
version = "0.10.0"
version = "0.10.1"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
18 changes: 18 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function ctgradient(f::Function, x::ctNumber; backend=__get_AD_backend())
return derivative(f, backend, x, extras)
end

function __ctgradient(f::Function, x::ctNumber)
return ForwardDiff.derivative(x -> f(x), x)
end

"""
$(TYPEDSIGNATURES)
Expand All @@ -88,13 +92,19 @@ function ctgradient(f::Function, x; backend=__get_AD_backend())
return gradient(f, backend, x, extras)
end

function __ctgradient(f::Function, x)
return ForwardDiff.gradient(f, x)
end

"""
$(TYPEDSIGNATURES)
Return the gradient of `X` at `x`.
"""
ctgradient(X::VectorField, x) = ctgradient(X.f, x)

__ctgradient(X::VectorField, x) = __ctgradient(X.f, x)

"""
$(TYPEDSIGNATURES)
Expand All @@ -107,6 +117,10 @@ function ctjacobian(f::Function, x::ctNumber; backend=__get_AD_backend())
return [der;;]
end

function __ctjacobian(f::Function, x::ctNumber)
return ForwardDiff.jacobian(x -> f(x[1]), [x])
end

"""
$(TYPEDSIGNATURES)
Expand All @@ -117,13 +131,17 @@ function ctjacobian(f::Function, x; backend=__get_AD_backend())
return jacobian(f, backend, x, extras)
end

__ctjacobian(f::Function, x) = ForwardDiff.jacobian(f, x)

"""
$(TYPEDSIGNATURES)
Return the Jacobian of `X` at `x`.
"""
ctjacobian(X::VectorField, x) = ctjacobian(X.f, x)

__ctjacobian(X::VectorField, x) = __ctjacobian(X.f, x)

"""
$(TYPEDSIGNATURES)
Expand Down

0 comments on commit 6f49f3f

Please sign in to comment.