-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help writing complex rules #744
Comments
This was referenced Apr 20, 2023
This will be fixed by #754 but will require a jll bump. |
Fixed by #754 |
Thanks! For completeness, this now works: julia> using Enzyme
julia> foo(x::Complex) = 2x;
julia> function EnzymeRules.augmented_primal(
config::EnzymeRules.ConfigWidth{1},
func::Const{typeof(foo)},
::Type{<:Active},
x::Active{<:Complex},
)
println("In custom augmented primal rule.")
# Compute primal
r = func.val(x.val)
if EnzymeRules.needs_primal(config)
primal = r
else
primal = nothing
end
if EnzymeRules.needs_shadow(config)
shadow = zero(r)
else
shadow = nothing
end
tape = nothing
return EnzymeRules.AugmentedReturn(primal, shadow, tape)
end
julia> function EnzymeRules.reverse(
config::EnzymeRules.ConfigWidth{1},
func::Const{typeof(foo)},
dret::Active{<:Complex},
tape,
y::Active{<:Complex},
)
println("In custom reverse rule.")
return (2*dret.val,)
end
julia> autodiff(Reverse, foo, Active, Active(1.0+3im))
In custom augmented primal rule.
In custom reverse rule.
((2.0 + 0.0im,),) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While writing #739, I ran into some difficulties defining rules for functions with complex inputs and outputs. Here's a simple example:
When I execute this rule, I get the following stacktrace:
I was surprised that Enzyme seems to insist on using Duplicated annotations for complex scalars. If I specify
Active
for the inputs as done above, they are replaced with aDuplicated
. Second, if I specifyshadow=nothing
, Enzyme complains that it expects theshadow
to be aComplexF64
, but if I make it aComplexF64
, then I see this error. How can I repair the above rules to work?The text was updated successfully, but these errors were encountered: