Skip to content

Commit b14ee60

Browse files
authored
Allow constant outputs in ForwardDiff (#526)
* Allow constant outputs in ForwardDiff * Partials of a constant are a zero-length tuple * Bump DI to 0.6.4
1 parent 665cc2c commit b14ee60

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

DifferentiationInterface/Project.toml

Lines changed: 1 addition & 1 deletion
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.3"
4+
version = "0.6.4"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

DifferentiationInterface/ext/DifferentiationInterfaceForwardDiffExt/utils.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ function make_dual!(::Type{T}, xdual, x, tx::NTuple{B}) where {T,B}
2828
return xdual .= Dual{T}.(x, tx...)
2929
end
3030

31-
myvalue(::Type{T}, ydual::Dual{T}) where {T} = value(T, ydual)
31+
myvalue(::Type{T}, ydual::Number) where {T} = value(T, ydual)
3232
myvalue(::Type{T}, ydual) where {T} = myvalue.(T, ydual)
3333
myvalue!(::Type{T}, y, ydual) where {T} = y .= myvalue.(T, ydual)
3434

35-
myderivative(::Type{T}, ydual::Dual{T}) where {T} = extract_derivative(T, ydual)
35+
myderivative(::Type{T}, ydual::Number) where {T} = extract_derivative(T, ydual)
3636
myderivative(::Type{T}, ydual) where {T} = myderivative.(T, ydual)
3737
myderivative!(::Type{T}, dy, ydual) where {T} = dy .= myderivative.(T, ydual)
3838

39-
function mypartials(::Type{T}, ::Val{B}, ydual::Dual) where {T,B}
40-
return partials(T, ydual).values
39+
function mypartials(::Type{T}, ::Val{B}, ydual::Number) where {T,B}
40+
return ntuple(Val(B)) do b
41+
partials(T, ydual, b)
42+
end
4143
end
4244

4345
function mypartials(::Type{T}, ::Val{B}, ydual) where {T,B}

0 commit comments

Comments
 (0)