Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick committed Sep 16, 2024
1 parent 24edc21 commit ee22f3a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,15 @@ end
@test z2d_compiled.c.a === z2d_fallback.c.a
@test z2d_compiled.c.b === z2d_fallback.c.b
end

@testset "ChainRules translation" begin
@test Zygote.wrap_chainrules_input(nothing) == ChainRules.ZeroTangent()
@test Zygote.wrap_chainrules_input((nothing,)) == ChainRules.ZeroTangent()
@test Zygote.wrap_chainrules_input([nothing]) == ChainRules.ZeroTangent()
@test Zygote.wrap_chainrules_input(((1.0, 2.0), 3.0)) == ChainRules.Tangent{Any}(ChainRules.Tangent{Any}(1.0, 2.0), 3.0)
@test Zygote.wrap_chainrules_input((; a = 1.0, b = 2.0)) == ChainRules.Tangent{Any}(a = 1.0, b = 2.0)
@test Zygote.wrap_chainrules_input(Ref(1)) == 1
@test Zygote.wrap_chainrules_input([2.0; 4.0]) == [2.0; 4.0]
@test Zygote.wrap_chainrules_input([[2.0; 4.0], [1.0; 3.0]]) == [[2.0; 4.0], [1.0; 3.0]]
@test Zygote.wrap_chainrules_input([nothing; 4.0]) == [0.0; 4.0] # ChainRules uses the numeric zero where possible
end

0 comments on commit ee22f3a

Please sign in to comment.