Skip to content

Commit cd34e2c

Browse files
committed
Add NoAutoDiff
1 parent 3ba3ecd commit cd34e2c

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
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.17.0"
4+
version = "1.18.0"
55

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

src/ADTypes.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export AutoChainRules,
4545
AutoTapir,
4646
AutoTaylorDiff,
4747
AutoTracker,
48-
AutoZygote
48+
AutoZygote,
49+
NoAutoDiff
4950
@public AbstractMode
5051
@public ForwardMode, ReverseMode, ForwardOrReverseMode, SymbolicMode
5152
@public mode

src/dense.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,20 @@ Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
515515
struct AutoZygote <: AbstractADType end
516516

517517
mode(::AutoZygote) = ReverseMode()
518+
519+
"""
520+
NoAutoDiff
521+
522+
Struct used to select no automatic differentiation.
523+
524+
Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
525+
526+
# Constructors
527+
528+
NoAutoDiff()
529+
"""
530+
struct NoAutoDiff <: AbstractADType end
531+
532+
function mode(::NoAutoDiff)
533+
throw(ArgumentError("No ADTypes.AbstractMode defined for NoAutoDiff()"))
534+
end

src/symbols.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
ADTypes.Auto(package::Symbol)
3+
ADTypes.Auto(nothing)::NoAutoDiff
34
45
A shortcut that converts an AD package name into an instance of [`AbstractADType`](@ref), with all parameters set to their default values.
56
@@ -27,3 +28,5 @@ for backend in (:ChainRules, :Diffractor, :Enzyme, :FastDifferentiation,
2728
@eval Auto(::Val{$(QuoteNode(backend))}, args...; kws...) = $(Symbol(:Auto, backend))(
2829
args...; kws...)
2930
end
31+
32+
Auto(::Nothing) = NoAutoDiff()

test/dense.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,10 @@ end
226226
@test ad isa AutoZygote
227227
@test mode(ad) isa ReverseMode
228228
end
229+
230+
@testset "NoAutoDiff" begin
231+
ad = NoAutoDiff()
232+
@test ad isa AbstractADType
233+
@test ad isa NoAutoDiff
234+
@test_throws ArgumentError mode(ad)
235+
end

test/symbols.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using Test
1515
@test ADTypes.Auto(:Tapir) isa AutoTapir
1616
@test ADTypes.Auto(:Tracker) isa AutoTracker
1717
@test ADTypes.Auto(:Zygote) isa AutoZygote
18+
@test ADTypes.Auto(nothing) isa NoAutoDiff
1819

1920
@test_throws MethodError ADTypes.Auto(:ThisPackageDoesNotExist)
2021
@test_throws UndefKeywordError ADTypes.Auto(:ChainRules)

0 commit comments

Comments
 (0)