Skip to content
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ChainRulesCore = "1.24"
EnumX = "1.0.4"
FindFirstFunctions = "1.3"
FiniteDifferences = "0.12.31"
ForwardDiff = "0.10.36"
ForwardDiff = "0.10.36, 1"
LinearAlgebra = "1.10"
Optim = "1.6"
PrettyTables = "2"
Expand Down
15 changes: 8 additions & 7 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ function derivative(A, t, order = 1)
_extrapolate_derivative_right(A, t, order)
else
iguess = A.iguesser
(order == 1) ? _derivative(A, t, iguess) :
ForwardDiff.derivative(t -> begin
_derivative(A, t, iguess)
end, t)
if order == 1
return _derivative(A, t, iguess)
end
return ForwardDiff.derivative(t -> begin
-_derivative(A, -t, iguess)
end, -t) # take derivative backwards in t to make it a left rather than right derivative
end
end

Expand Down Expand Up @@ -313,9 +315,8 @@ function _derivative(
ducum = (A.c[ax_u..., 2] - A.c[ax_u..., 1]) / (A.k[A.d + 2])
else
for i in 1:(A.h - 1)
ducum = ducum +
sc[i + 1] * (A.c[ax_u..., i + 1] - A.c[ax_u..., i]) /
(A.k[i + A.d + 1] - A.k[i + 1])
ducum += sc[i + 1] * (A.c[ax_u..., i + 1] - A.c[ax_u..., i]) /
(A.k[i + A.d + 1] - A.k[i + 1])
end
end
ducum * A.d * scale
Expand Down
9 changes: 3 additions & 6 deletions test/derivative_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Symbolics
using StableRNGs
using RegularizationTools
using Optim
using ForwardDiff
import ForwardDiff
using LinearAlgebra

function test_derivatives(method; args = [], kwargs = [], name::String)
Expand Down Expand Up @@ -35,11 +35,8 @@ function test_derivatives(method; args = [], kwargs = [], name::String)

# Interpolation transition points
for _t in t[2:(end - 1)]
if func isa Union{BSplineInterpolation, BSplineApprox,
CubicHermiteSpline}
fdiff = forward_fdm(5, 1; geom = true)(func, _t)
fdiff2 = forward_fdm(5, 1; geom = true)(t -> derivative(func, t), _t)
elseif func isa SmoothedConstantInterpolation
if func isa Union{SmoothedConstantInterpolation, BSplineInterpolation, BSplineApprox}
# TODO fix interpolations
continue
else
fdiff = backward_fdm(5, 1; geom = true)(func, _t)
Expand Down
Loading