Skip to content

Commit 2aafe20

Browse files
1-Bart-1gdalle
andauthored
Add the relstep and absstep parameters to AutoFiniteDiff (#102)
* add relstep and absstep to AutoFiniteDiff * add relstep and absstep documentation * add tests for relstep and absstep * Fix typo in doc Co-authored-by: Guillaume Dalle <[email protected]> * improve step test Co-authored-by: Guillaume Dalle <[email protected]> * improve step test Co-authored-by: Guillaume Dalle <[email protected]> * update minor version --------- Co-authored-by: Guillaume Dalle <[email protected]>
1 parent e3e2d1a commit 2aafe20

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
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.11.0"
4+
version = "1.12.0"
55

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

src/dense.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,22 @@ Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
106106
107107
# Constructors
108108
109-
AutoFiniteDiff(; fdtype=Val(:forward), fdjtype=fdtype, fdhtype=Val(:hcentral))
109+
AutoFiniteDiff(; fdtype=Val(:forward), fdjtype=fdtype, fdhtype=Val(:hcentral), relstep=nothing, absstep=nothing)
110110
111111
# Fields
112112
113113
- `fdtype::T1`: finite difference type
114114
- `fdjtype::T2`: finite difference type for the Jacobian
115115
- `fdhtype::T3`: finite difference type for the Hessian
116+
- `relstep`: relative finite difference step size
117+
- `absstep`: absolute finite difference step size
116118
"""
117119
Base.@kwdef struct AutoFiniteDiff{T1, T2, T3} <: AbstractADType
118120
fdtype::T1 = Val(:forward)
119121
fdjtype::T2 = fdtype
120122
fdhtype::T3 = Val(:hcentral)
123+
relstep = nothing
124+
absstep = nothing
121125
end
122126

123127
mode(::AutoFiniteDiff) = ForwardMode()
@@ -129,7 +133,11 @@ function Base.show(io::IO, backend::AutoFiniteDiff)
129133
backend.fdjtype != backend.fdtype &&
130134
print(io, "fdjtype=", repr(backend.fdjtype; context = io), ", ")
131135
backend.fdhtype != Val(:hcentral) &&
132-
print(io, "fdhtype=", repr(backend.fdhtype; context = io))
136+
print(io, "fdhtype=", repr(backend.fdhtype; context = io), ", ")
137+
!isnothing(backend.relstep) &&
138+
print(io, "relstep=", repr(backend.relstep; context = io), ", ")
139+
!isnothing(backend.absstep) &&
140+
print(io, "absstep=", repr(backend.absstep; context = io))
133141
print(io, ")")
134142
end
135143

test/dense.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ end
6767
@test ad.fdtype === Val(:forward)
6868
@test ad.fdjtype === Val(:forward)
6969
@test ad.fdhtype === Val(:hcentral)
70+
@test ad.relstep === nothing
71+
@test ad.absstep === nothing
7072

71-
ad = AutoFiniteDiff(; fdtype = Val(:central), fdjtype = Val(:forward))
73+
ad = AutoFiniteDiff(; fdtype = Val(:central), fdjtype = Val(:forward), relstep = 1e-3, absstep = 1e-4)
7274
@test ad isa AbstractADType
7375
@test ad isa AutoFiniteDiff
7476
@test mode(ad) isa ForwardMode
7577
@test ad.fdtype === Val(:central)
7678
@test ad.fdjtype === Val(:forward)
7779
@test ad.fdhtype === Val(:hcentral)
80+
@test ad.relstep == 1e-3
81+
@test ad.absstep == 1e-4
7882
end
7983

8084
@testset "AutoFiniteDifferences" begin

0 commit comments

Comments
 (0)