-
Notifications
You must be signed in to change notification settings - Fork 15
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
Automatic tangent generation for simple types #43
Conversation
I donb't think it should need a generated function. |
I think this needs a docstring that describes |
Co-authored-by: Lyndon White <[email protected]>
@oxinabox I've got a weird test failure. Would you mind taking a look? It's in some of your more complex code, so might be obvious to you what's going on. |
Which error? https://travis-ci.com/github/JuliaDiff/ChainRulesTestUtils.jl/jobs/354027267#L263-L264 Errors on 1.3 and earlier about Could port that change into Compat.jl |
Nah, this error: generate_tangent: Error During Test at /Users/willtebbutt/.julia/dev/ChainRulesTestUtils/test/generate_tangent.jl:25
Test threw exception
Expression: x + rand_tangent(rng, x) isa typeof(x)
MethodError: Cannot `convert` an object of type Int64 to an object of type DoesNotExist
Closest candidates are:
convert(::Type{T}, !Matched::T) where T at essentials.jl:171
Stacktrace:
[1] convert(::Type{Tuple{DoesNotExist}}, ::Tuple{Int64}) at ./essentials.jl:310 (repeats 2 times)
[2] Tuple{Float64,DoesNotExist}(::Tuple{Float64,Int64}) at ./tuple.jl:225
[3] NamedTuple{(:a, :b),Tuple{Float64,DoesNotExist}}(::Tuple{Float64,Int64}) at ./namedtuple.jl:72
[4] macro expansion at /Users/willtebbutt/.julia/packages/ChainRulesCore/Q5Nrj/src/differentials/composite.jl:0 [inlined]
[5] elementwise_add(::NamedTuple{(:a, :b),Tuple{Float64,Int64}}, ::NamedTuple{(:a, :b),Tuple{Float64,DoesNotExist}}) at /Users/willtebbutt/.julia/packages/ChainRulesCore/Q5Nrj/src/differentials/composite.jl:191
[6] +(::NamedTuple{(:a, :b),Tuple{Float64,Int64}}, ::Composite{NamedTuple{(:a, :b),Tuple{Float64,Int64}},NamedTuple{(:a, :b),Tuple{Float64,DoesNotExist}}}) at /Users/willtebbutt/.julia/packages/ChainRulesCore/Q5Nrj/src/differential_arithmetic.jl:88
[7] (::var"#3#4"{MersenneTwister})(::Tuple{NamedTuple{(:a, :b),Tuple{Float64,Int64}},UnionAll}) at /Users/willtebbutt/.julia/dev/ChainRulesTestUtils/test/generate_tangent.jl:25
[8] foreach(::var"#3#4"{MersenneTwister}, ::Array{Tuple{Any,Type},1}) at ./abstractarray.jl:1919
[9] top-level scope at /Users/willtebbutt/.julia/dev/ChainRulesTestUtils/test/generate_tangent.jl:6
[10] top-level scope at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/Test/src/Test.jl:1113
[11] top-level scope at /Users/willtebbutt/.julia/dev/ChainRulesTestUtils/test/generate_tangent.jl:4 Appears to stem from the |
AH yes that is a bug in ChainRulesCore. I will fix it |
@oxinabox your fix in ChainRulesCore appears to have fixed the issue. Thanks for the quick fix. |
Co-authored-by: Seth Axen <[email protected]>
Co-authored-by: Seth Axen <[email protected]>
Unless there's more you want to add, I think all this is missing is |
I think |
I also still definitely want to add stuff that can handle |
TIL that |
Co-authored-by: Lyndon White <[email protected]>
Co-authored-by: Lyndon White <[email protected]>
@oxinabox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, once the rng part is cleared up.
Revert to |
First steps of an implementation to automatically construct appropriate tangent vectors. @oxinabox @sethaxen let me know if you think these are okay as a starting point / if you think that there are any other types that are crucial to have this implemented for.
I would very much like to cover general structs with a generated function, but I've not had a chance to sort that out yet.