Skip to content

Add dir field to AutoFiniteDiff #106

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

Merged
merged 6 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -1,7 +1,7 @@
name = "ADTypes"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
authors = ["Vaibhav Dixit <[email protected]>, Guillaume Dalle and contributors"]
version = "1.12.1"
version = "1.13.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
8 changes: 6 additions & 2 deletions src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
- `fdhtype::T3`: finite difference type for the Hessian
- `relstep`: relative finite difference step size
- `absstep`: absolute finite difference step size
- `dir`: direction of the finite difference step
"""
Base.@kwdef struct AutoFiniteDiff{T1, T2, T3, S1, S2} <: AbstractADType
Base.@kwdef struct AutoFiniteDiff{T1, T2, T3, S1, S2, S3} <: AbstractADType
fdtype::T1 = Val(:forward)
fdjtype::T2 = fdtype
fdhtype::T3 = Val(:hcentral)
relstep::S1 = nothing
absstep::S2 = nothing
dir::S3 = true
end

mode(::AutoFiniteDiff) = ForwardMode()
Expand All @@ -137,7 +139,9 @@ function Base.show(io::IO, backend::AutoFiniteDiff)
!isnothing(backend.relstep) &&
print(io, "relstep=", repr(backend.relstep; context = io), ", ")
!isnothing(backend.absstep) &&
print(io, "absstep=", repr(backend.absstep; context = io))
print(io, "absstep=", repr(backend.absstep; context = io), ", ")
!backend.dir &&
print(io, "dir=", repr(backend.dir; context = io))
print(io, ")")
end

Expand Down
4 changes: 3 additions & 1 deletion test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ end
@test ad.fdhtype === Val(:hcentral)
@test ad.relstep === nothing
@test ad.absstep === nothing
@test ad.dir

ad = AutoFiniteDiff(; fdtype = Val(:central), fdjtype = Val(:forward), relstep = 1e-3, absstep = 1e-4)
ad = AutoFiniteDiff(; fdtype = Val(:central), fdjtype = Val(:forward), relstep = 1e-3, absstep = 1e-4, dir = false)
@test ad isa AbstractADType
@test ad isa AutoFiniteDiff
@test mode(ad) isa ForwardMode
Expand All @@ -79,6 +80,7 @@ end
@test ad.fdhtype === Val(:hcentral)
@test ad.relstep == 1e-3
@test ad.absstep == 1e-4
@test !ad.dir
end

@testset "AutoFiniteDifferences" begin
Expand Down