-
Notifications
You must be signed in to change notification settings - Fork 3
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
Interoperability with dual numbers #196
Comments
Maybe we're running into the issue described here: https://docs.julialang.org/en/v1/manual/methods/#Abstract-containers-and-element-types |
Replicated via julia> using SparseConnectivityTracer, ForwardDiff
julia> using ForwardDiff: Dual, Partials, Tag
julia> d = Dual{Tag{*,Float64}}(1.2, 3.4)
Dual{Tag{*, Float64}}(1.2,3.4)
julia> jacobian_sparsity(x -> x*d, 1.0, TracerSparsityDetector())
ERROR: MethodError: *(::SparseConnectivityTracer.GradientTracer{…}, ::Dual{…}) is ambiguous.
Candidates:
*(tx::SparseConnectivityTracer.GradientTracer, ::Real)
@ SparseConnectivityTracer ~/Developer/SparseConnectivityTracer.jl/src/overloads/gradient_tracer.jl:125
*(x::Real, y::Dual{Ty}) where Ty
@ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/dual.jl:145
Possible fix, define
*(::SparseConnectivityTracer.GradientTracer, ::Dual{Ty}) where Ty
[...]
julia> jacobian_sparsity(x -> x*d, 1.0, TracerLocalSparsityDetector())
ERROR: MethodError: *(::SparseConnectivityTracer.Dual{Float64, SparseConnectivityTracer.GradientTracer{…}}, ::Dual{Tag{…}, Float64, 1}) is ambiguous.
Candidates:
*(dx::D, y::Real) where {P, T<:SparseConnectivityTracer.GradientTracer, D<:SparseConnectivityTracer.Dual{P, T}}
@ SparseConnectivityTracer ~/Developer/SparseConnectivityTracer.jl/src/overloads/gradient_tracer.jl:172
*(x::Real, y::Dual{Ty}) where Ty
@ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/dual.jl:145
Possible fix, define
*(::D, ::Dual{Ty}) where {Ty, P, T<:SparseConnectivityTracer.GradientTracer, D<:SparseConnectivityTracer.Dual{P, T}}
[...] Looks like this is just a "regular" method ambiguity error. |
If this is a desired feature, we should rework the function overloading utilities for 2-to-1 functions to accept an optional type argument. Then you could add a package extension for ForwardDiff and call something like eval(SCT.generate_code_2_to_1(:Base, Dual, ops_2_to_1)) However, I'm not sure we can make this work in combination with other package extensions. |
Essentially the more general takeaway is that SCT doesn't play nice with other packages based on operator overloading |
Maybe for operations between a |
More generally packages implementing custom methods for 2-to-1 Base functions.
I'm not sure how we would hit type promotion if the method call itself is ambiguous. |
Basic operators from Julia Base should now work with |
After thinking about it for a day, I'm starting to think #200 shouldn't be released. While this is a general issue with |
I agree with that, good catch. |
#200 has been reverted. The newly tagged |
I want to obtain the Jacobian sparsity of a function whose body contains a
ForwardDiff.derivative
call. This leads to this error:Does this have a quick fix?
Edit: I worked around it, so you can close the issue if you don't find this important.
The text was updated successfully, but these errors were encountered: