Skip to content

Commit 1f87272

Browse files
authored
feat: support contexts with symbolic backends (#703)
* feat: support contexts with symbolic backends * No `myvec`
1 parent 43a6e47 commit 1f87272

11 files changed

Lines changed: 847 additions & 470 deletions

File tree

DifferentiationInterface/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DifferentiationInterface"
22
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
33
authors = ["Guillaume Dalle", "Adrian Hill"]
4-
version = "0.6.33"
4+
version = "0.6.34"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -55,7 +55,7 @@ Diffractor = "=0.2.6"
5555
Enzyme = "0.13.17"
5656
EnzymeCore = "0.8.8"
5757
ExplicitImports = "1.10.1"
58-
FastDifferentiation = "0.4.1"
58+
FastDifferentiation = "0.4.3"
5959
FiniteDiff = "2.23.1"
6060
FiniteDifferences = "0.12.31"
6161
ForwardDiff = "0.10.36"

DifferentiationInterface/docs/src/explanation/backends.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@ In practice, many AD backends have custom implementations for high-level operato
5656

5757
Moreover, each context type is supported by a specific subset of backends:
5858

59-
| | [`Constant`](@ref) |
60-
| -------------------------- | ------------------ |
61-
| `AutoChainRules` ||
62-
| `AutoDiffractor` ||
63-
| `AutoEnzyme` (forward) ||
64-
| `AutoEnzyme` (reverse) ||
65-
| `AutoFastDifferentiation` | |
66-
| `AutoFiniteDiff` ||
67-
| `AutoFiniteDifferences` ||
68-
| `AutoForwardDiff` ||
69-
| `AutoGTPSA` ||
70-
| `AutoMooncake` ||
71-
| `AutoPolyesterForwardDiff` ||
72-
| `AutoReverseDiff` ||
73-
| `AutoSymbolics` | |
74-
| `AutoTracker` ||
75-
| `AutoZygote` ||
59+
| | [`Constant`](@ref) | [`Cache`](@ref) |
60+
| -------------------------- | ------------------ | --------------- |
61+
| `AutoChainRules` |||
62+
| `AutoDiffractor` |||
63+
| `AutoEnzyme` (forward) |||
64+
| `AutoEnzyme` (reverse) |||
65+
| `AutoFastDifferentiation` | | |
66+
| `AutoFiniteDiff` |||
67+
| `AutoFiniteDifferences` |||
68+
| `AutoForwardDiff` |||
69+
| `AutoGTPSA` |||
70+
| `AutoMooncake` |||
71+
| `AutoPolyesterForwardDiff` |||
72+
| `AutoReverseDiff` |||
73+
| `AutoSymbolics` | | |
74+
| `AutoTracker` |||
75+
| `AutoZygote` |||
7676

7777
## Second order
7878

DifferentiationInterface/ext/DifferentiationInterfaceFastDifferentiationExt/DifferentiationInterfaceFastDifferentiationExt.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ using FastDifferentiation.RuntimeGeneratedFunctions: RuntimeGeneratedFunction
1818

1919
DI.check_available(::AutoFastDifferentiation) = true
2020

21-
monovec(x::Number) = [x]
22-
23-
myvec(x::Number) = monovec(x)
21+
myvec(x::Number) = [x]
2422
myvec(x::AbstractArray) = vec(x)
2523

24+
variablize(::Number, name::Symbol) = only(make_variables(name))
25+
variablize(x::AbstractArray, name::Symbol) = make_variables(name, size(x)...)
26+
27+
function variablize(contexts::NTuple{C,DI.Context}) where {C}
28+
map(enumerate(contexts)) do (k, c)
29+
variablize(DI.unwrap(c), Symbol("context$k"))
30+
end
31+
end
32+
2633
dense_ad(backend::AutoFastDifferentiation) = backend
2734
dense_ad(backend::AutoSparse{<:AutoFastDifferentiation}) = ADTypes.dense_ad(backend)
2835

36+
myvec_unwrap(x) = myvec(DI.unwrap(x))
37+
2938
include("onearg.jl")
3039
include("twoarg.jl")
3140

0 commit comments

Comments
 (0)