forked from JuliaDiff/Diffractor.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractDifferentiationTests.jl
More file actions
74 lines (66 loc) · 3.39 KB
/
AbstractDifferentiationTests.jl
File metadata and controls
74 lines (66 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module AbstractDifferentiationTests
using AbstractDifferentiation, Diffractor, Test, LinearAlgebra, ChainRulesCore
import AbstractDifferentiation as AD
backend = Diffractor.DiffractorForwardBackend()
@testset "bundle" begin
bundle = Diffractor.bundle
@test bundle(1.0, 2.0) isa Diffractor.TaylorBundle{1}
@test bundle([1.0, 2.0], [2.0, 3.0]) isa Diffractor.TaylorBundle{1}
@test bundle(1.5=>2.5, Tangent{Pair{Float64, Float64}}(first=1.0, second=2.0)) isa Diffractor.TaylorBundle{1}
@test bundle(1.1, ChainRulesCore.ZeroTangent()) isa Diffractor.ZeroBundle{1}
@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.TaylorBundle{1}
# noncanonical structural tangent
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)))
t = Diffractor.first_partial(b)
@test b isa Diffractor.TaylorBundle{1}
@test iszero(t.first)
@test t.second.first == 1.0
@test t.second.second == 2.0
end
@testset "basics" begin
@test AD.derivative(backend, +, 1.5, 10.0) == (1.0, 1.0)
@test AD.derivative(backend, *, 1.5, 10.0) == (10.0, 1.5)
@test only(AD.jacobian(backend, prod, [1.5, 2.5, 10.0])) == [25.0 15.0 3.75]
@test only(AD.jacobian(backend, identity, [1.5, 2.5, 10.0])) == Matrix(I, 3, 3)
end
# standard tests from AbstractDifferentiation.test_utils
include(joinpath(pathof(AbstractDifferentiation), "..", "..", "test", "test_utils.jl"))
@testset "Standard AbstractDifferentiation.test_utils tests" begin
backends = [
@inferred(Diffractor.DiffractorForwardBackend())
]
@testset for backend in backends
@test backend isa AD.AbstractForwardMode
@testset "Derivative" begin
test_derivatives(backend)
end
@testset "Gradient" begin # no method matching size(::ZeroTangent)
@test_broken test_gradients(backend)
end
@testset "Jacobian" begin #setfield!(::Core.Box, ::Symbol, ::Vector{Float64})
test_jacobians(backend)
end
@testset "Hessian" begin # no method matching (Diffractor.TangentBundle{…} where P)(::Tuple{…}, ::Tuple{…})
@test_broken test_hessians(backend)
end
@testset "jvp" begin # Expression: pf1[1] isa Vector{Float64}
@test_broken false # test_jvp(backend; vaugmented=true)
end
@testset "j′vp" begin # no method matching *(::Diffractor.PrimeDerivativeBack{1, Diagonal{Bool, Vector{Bool}}}, ::Vector{Float64})
@test_broken false #test_j′vp(backend)
end
@testset "Lazy Derivative" begin
test_lazy_derivatives(backend)
end
@testset "Lazy Gradient" begin #MethodError: no method matching size(::ZeroTangent)
@test_broken test_lazy_gradients(backend)
end
@testset "Lazy Jacobian" begin # no method matching *(::Diffractor.PrimeDerivativeBack{1, Diagonal{Bool, Vector{Bool}}}, ::Vector{Float64})
@test_broken false #test_lazy_jacobians(backend)
end
@testset "Lazy Hessian" begin # ERROR: MethodError: no method matching *(::Vector{Float64}, ::Diffractor.PrimeDerivativeBack{1, Vector{Float64}})
@test_broken false #test_lazy_hessians(backend)
end
end
end
end #module AbstractDifferentiationTests