Skip to content

Commit 4b707db

Browse files
jClugstorgdalle
andauthored
Add dir field to AutoFiniteDiff (#106)
* add dir field to AutoFiniteDiff * add dir to docstrings and tests * increment minor version * Update src/dense.jl * fix printing * Add test --------- Co-authored-by: Guillaume Dalle <[email protected]>
1 parent 9f558f0 commit 4b707db

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ADTypes"
22
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
33
authors = ["Vaibhav Dixit <[email protected]>, Guillaume Dalle and contributors"]
4-
version = "1.12.1"
4+
version = "1.13.0"
55

66
[deps]
77
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/dense.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,15 @@ Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
115115
- `fdhtype::T3`: finite difference type for the Hessian
116116
- `relstep`: relative finite difference step size
117117
- `absstep`: absolute finite difference step size
118+
- `dir`: direction of the finite difference step
118119
"""
119-
Base.@kwdef struct AutoFiniteDiff{T1, T2, T3, S1, S2} <: AbstractADType
120+
Base.@kwdef struct AutoFiniteDiff{T1, T2, T3, S1, S2, S3} <: AbstractADType
120121
fdtype::T1 = Val(:forward)
121122
fdjtype::T2 = fdtype
122123
fdhtype::T3 = Val(:hcentral)
123124
relstep::S1 = nothing
124125
absstep::S2 = nothing
126+
dir::S3 = true
125127
end
126128

127129
mode(::AutoFiniteDiff) = ForwardMode()
@@ -137,7 +139,9 @@ function Base.show(io::IO, backend::AutoFiniteDiff)
137139
!isnothing(backend.relstep) &&
138140
print(io, "relstep=", repr(backend.relstep; context = io), ", ")
139141
!isnothing(backend.absstep) &&
140-
print(io, "absstep=", repr(backend.absstep; context = io))
142+
print(io, "absstep=", repr(backend.absstep; context = io), ", ")
143+
backend.dir != true &&
144+
print(io, "dir=", repr(backend.dir; context = io))
141145
print(io, ")")
142146
end
143147

test/dense.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ end
6969
@test ad.fdhtype === Val(:hcentral)
7070
@test ad.relstep === nothing
7171
@test ad.absstep === nothing
72+
@test ad.dir
7273

73-
ad = AutoFiniteDiff(; fdtype = Val(:central), fdjtype = Val(:forward), relstep = 1e-3, absstep = 1e-4)
74+
ad = AutoFiniteDiff(; fdtype = Val(:central), fdjtype = Val(:forward), relstep = 1e-3, absstep = 1e-4, dir = false)
7475
@test ad isa AbstractADType
7576
@test ad isa AutoFiniteDiff
7677
@test mode(ad) isa ForwardMode
@@ -79,6 +80,7 @@ end
7980
@test ad.fdhtype === Val(:hcentral)
8081
@test ad.relstep == 1e-3
8182
@test ad.absstep == 1e-4
83+
@test !ad.dir
8284
end
8385

8486
@testset "AutoFiniteDifferences" begin

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function every_ad_with_options()
6363
AutoEnzyme(mode = :forward),
6464
AutoFastDifferentiation(),
6565
AutoFiniteDiff(),
66-
AutoFiniteDiff(fdtype = :fd, fdjtype = :fdj, fdhtype = :fdh),
66+
AutoFiniteDiff(fdtype = :fd, fdjtype = :fdj, fdhtype = :fdh,
67+
relstep = 1, absstep = 2, dir = false),
6768
AutoFiniteDifferences(; fdm = :fdm),
6869
AutoForwardDiff(),
6970
AutoForwardDiff(chunksize = 3, tag = :tag),

0 commit comments

Comments
 (0)