-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1f850b
commit c11dd72
Showing
5 changed files
with
78 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module TaylorDiffZygoteExt | ||
|
||
using TaylorDiff | ||
import Zygote: @adjoint, Numeric, _dual_safearg, ZygoteRuleConfig | ||
using ChainRulesCore: @opt_out | ||
|
||
# Zygote can't infer this constructor function | ||
# defining rrule for this doesn't seem to work for Zygote | ||
# so need to use @adjoint | ||
@adjoint TaylorScalar{T, N}(t::TaylorScalar{T, M}) where {T, N, M} = TaylorScalar{T, N}(t), | ||
x̄ -> (TaylorScalar{T, M}(x̄),) | ||
|
||
# Zygote will try to use ForwardDiff to compute broadcast functions | ||
# However, TaylorScalar is not dual safe, so we opt out of this | ||
_dual_safearg(::Numeric{<:TaylorScalar}) = false | ||
|
||
# Zygote has a rule for literal power, need to opt out of this | ||
@opt_out rrule( | ||
::ZygoteRuleConfig, ::typeof(Base.literal_pow), ::typeof(^), x::TaylorScalar, ::Val{p} | ||
) where {p} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters