Skip to content
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

Test that keyword arguments are correct #781

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,32 @@ end
@test (x->10*(x => 2)[1])'(100) === 10
@test (x->10*(x => 2)[2])'(100) === 0
end

# https://github.com/JuliaDiff/ChainRules.jl/issues/257
@testset "Keyword Argument Passing" begin
struct Type1{VJP}
x::VJP
end

struct Type2{compile}
Type2(compile=false) = new{compile}()
end

function loss_adjoint(θ)
sum(f(sensealg=Type1(Type2(true))))
end

i = 1
global x = Any[nothing,nothing]

Zygote.@nograd g(x,i,sensealg) = Main.x[i] = sensealg
function f(;sensealg=nothing)
g(x,i,sensealg)
return rand(100)
end

loss_adjoint([1.0])
i = 2
Zygote.gradient(loss_adjoint,[1.0])
@test x[1] == x[2]
end