|
1 |
| -using AbstractDifferentiation, Diffractor, Test, LinearAlgebra |
| 1 | +using AbstractDifferentiation, Diffractor, Test, LinearAlgebra, ChainRulesCore |
2 | 2 | import AbstractDifferentiation as AD
|
3 | 3 | backend = Diffractor.DiffractorForwardBackend()
|
4 | 4 |
|
| 5 | +@testset "bundle" begin |
| 6 | + bundle = Diffractor.bundle |
| 7 | + |
| 8 | + @test bundle(1.0, 2.0) isa Diffractor.TaylorBundle{1} |
| 9 | + @test bundle([1.0, 2.0], [2.0, 3.0]) isa Diffractor.TaylorBundle{1} |
| 10 | + @test bundle(1.5=>2.5, Tangent{Pair{Float64, Float64}}(first=1.0, second=2.0)) isa Diffractor.CompositeBundle{1} |
| 11 | + @test bundle(1.1, ChainRulesCore.ZeroTangent()) isa Diffractor.ZeroBundle{1} |
| 12 | + @test bundle(1.5=>2.5=>3.5, Tangent{Pair{Float64, Pair{Float64, Float64}}}(first=1.0, second=Tangent{Pair{Float64, Float64}}(first=1.0, second=2.0))) isa Diffractor.CompositeBundle{1} |
| 13 | + |
| 14 | + # noncanonical structural tangent |
| 15 | + b = bundle(1.5=>2.5=>3.5, Tangent{Pair{Float64, Pair{Float64, Float64}}}(second=Tangent{Pair{Float64, Float64}}(second=2.0, first=1.0))) |
| 16 | + t = Diffractor.first_partial(b) |
| 17 | + @test b isa Diffractor.CompositeBundle{1} |
| 18 | + @test iszero(t.first) |
| 19 | + @test t.second.first == 1.0 |
| 20 | + @test t.second.second == 2.0 |
| 21 | +end |
| 22 | + |
5 | 23 | @testset "basics" begin
|
6 | 24 | @test AD.derivative(backend, +, 1.5, 10.0) == (1.0, 1.0)
|
7 | 25 | @test AD.derivative(backend, *, 1.5, 10.0) == (10.0, 1.5)
|
@@ -50,3 +68,4 @@ include(joinpath(pathof(AbstractDifferentiation), "..", "..", "test", "test_util
|
50 | 68 | end
|
51 | 69 | end
|
52 | 70 | end
|
| 71 | + |
0 commit comments