|
82 | 82 |
|
83 | 83 | @inline value(::Type{T}, x) where T = x
|
84 | 84 | @inline value(::Type{T}, d::Dual{T}) where T = value(d)
|
85 |
| -function value(::Type{T}, d::Dual{S}) where {T,S} |
86 |
| - # TODO: in the case of nested Duals, it may be possible to "transpose" the Dual objects |
87 |
| - throw(DualMismatchError(T,S)) |
| 85 | +@inline function value(::Type{T}, d::Dual{S}) where {T,S} |
| 86 | + if S ≺ T |
| 87 | + d |
| 88 | + else |
| 89 | + throw(DualMismatchError(T,S)) |
| 90 | + end |
88 | 91 | end
|
89 | 92 |
|
90 | 93 | @inline partials(x) = Partials{0,typeof(x)}(tuple())
|
|
96 | 99 |
|
97 | 100 | @inline Base.@propagate_inbounds partials(::Type{T}, x, i...) where T = partials(x, i...)
|
98 | 101 | @inline Base.@propagate_inbounds partials(::Type{T}, d::Dual{T}, i...) where T = partials(d, i...)
|
99 |
| -partials(::Type{T}, d::Dual{S}, i...) where {T,S} = throw(DualMismatchError(T,S)) |
| 102 | +@inline function partials(::Type{T}, d::Dual{S}, i...) where {T,S} |
| 103 | + if S ≺ T |
| 104 | + zero(d) |
| 105 | + else |
| 106 | + throw(DualMismatchError(T,S)) |
| 107 | + end |
| 108 | +end |
| 109 | + |
100 | 110 |
|
101 | 111 | @inline npartials(::Dual{T,V,N}) where {T,V,N} = N
|
102 | 112 | @inline npartials(::Type{Dual{T,V,N}}) where {T,V,N} = N
|
|
0 commit comments