Skip to content

Commit

Permalink
Merge pull request #11 from SciML/dw/finitedifferences
Browse files Browse the repository at this point in the history
Add AD type for FiniteDifferences
  • Loading branch information
Vaibhavdixit02 authored Jul 19, 2023
2 parents d19986f + 7c5cfe2 commit 76daa27
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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 <vaibhavyashdixit@gmail.com> and contributors"]
version = "0.1.5"
version = "0.1.6"

[compat]
julia = "1"
Expand Down
8 changes: 7 additions & 1 deletion src/ADTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function AutoFiniteDiff(; fdtype = Val(:forward), fdjtype = fdtype,
AutoFiniteDiff(fdtype, fdjtype, fdhtype)
end

struct AutoFiniteDifferences{T} <: AbstractADType
fdm::T
end

AutoFiniteDifferences(; fdm = nothing) = AutoFiniteDifferences(fdm)

struct AutoForwardDiff{chunksize} <: AbstractADType end

function AutoForwardDiff(chunksize = nothing)
Expand Down Expand Up @@ -51,5 +57,5 @@ function AutoSparseForwardDiff(chunksize = nothing)
AutoSparseForwardDiff{chunksize}()
end

export AutoFiniteDiff, AutoForwardDiff, AutoReverseDiff, AutoZygote, AutoEnzyme, AutoTracker, AutoModelingToolkit, AutoSparseFiniteDiff, AutoSparseForwardDiff
export AutoFiniteDiff, AutoFiniteDifferences, AutoForwardDiff, AutoReverseDiff, AutoZygote, AutoEnzyme, AutoTracker, AutoModelingToolkit, AutoSparseFiniteDiff, AutoSparseForwardDiff
end
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ using Test
@test adtype isa ADTypes.AbstractADType
@test adtype isa AutoFiniteDiff

adtype = AutoFiniteDifferences()
@test adtype isa ADTypes.AbstractADType
@test adtype isa AutoFiniteDifferences{Nothing}

# In practice, you would rather specify a
# `fdm::FiniteDifferences.FiniteDifferenceMethod`, e.g. constructed with
# `FiniteDifferences.central_fdm` or `FiniteDifferences.forward_fdm`
adtype = AutoFiniteDifferences(; fdm = Val(:forward))
@test adtype isa ADTypes.AbstractADType
@test adtype isa AutoFiniteDifferences{Val{:forward}}

adtype = AutoForwardDiff()
@test adtype isa ADTypes.AbstractADType
@test adtype isa AutoForwardDiff
Expand Down

0 comments on commit 76daa27

Please sign in to comment.