1
- using FiniteDifferences: rand_tangent
2
-
3
- @testset " generate_tangent" begin
1
+ # Test struct for `rand_tangent` and `difference`.
2
+ struct Bar
3
+ a:: Float64
4
+ b:: Int
5
+ c:: Any
6
+ end
7
+ @testset " rand_tangent" begin
4
8
rng = MersenneTwister (123456 )
5
9
6
10
@testset " Primal: $(typeof (x)) , Tangent: $T_tangent " for (x, T_tangent) in [
@@ -13,9 +17,9 @@ using FiniteDifferences: rand_tangent
13
17
(4 , NoTangent),
14
18
(FiniteDifferences, NoTangent), # Module object
15
19
# Types (not instances of type)
16
- (Foo , NoTangent),
17
- (Union{Int, Foo }, NoTangent),
18
- (Union{Int, Foo }, NoTangent),
20
+ (Bar , NoTangent),
21
+ (Union{Int, Bar }, NoTangent),
22
+ (Union{Int, Bar }, NoTangent),
19
23
(Vector, NoTangent),
20
24
(Vector{Float64}, NoTangent),
21
25
(Integer, NoTangent),
@@ -49,8 +53,8 @@ using FiniteDifferences: rand_tangent
49
53
((a= 5.0 , b= 1 ), Tangent{NamedTuple{(:a , :b ), Tuple{Float64, Int}}}),
50
54
51
55
# structs.
52
- (Foo (5.0 , 4 , rand (rng, 3 )), Tangent{Foo }),
53
- (Foo (4.0 , 3 , Foo (5.0 , 2 , 4 )), Tangent{Foo }),
56
+ (Bar (5.0 , 4 , rand (rng, 3 )), Tangent{Bar }),
57
+ (Bar (4.0 , 3 , Bar (5.0 , 2 , 4 )), Tangent{Bar }),
54
58
(sin, NoTangent),
55
59
# all fields NoTangent implies NoTangent
56
60
(Pair (:a , " b" ), NoTangent),
@@ -66,14 +70,6 @@ using FiniteDifferences: rand_tangent
66
70
Diagonal (randn (2 )),
67
71
Tangent{Diagonal{Float64, Vector{Float64}}},
68
72
),
69
- (
70
- SVector {2, Float64} (1.0 , 2.0 ),
71
- Tangent{typeof (SVector {2, Float64} (1.0 , 2.0 ))},
72
- ),
73
- (
74
- SMatrix {2, 2, ComplexF64} (1.0 , 2.0 , 3.0 , 4.0 ),
75
- Tangent{typeof (SMatrix {2, 2, ComplexF64} (1.0 , 2.0 , 3.0 , 4.0 ))},
76
- ),
77
73
(
78
74
Symmetric (randn (2 , 2 )),
79
75
Tangent{Symmetric{Float64, Matrix{Float64}}},
@@ -93,7 +89,7 @@ using FiniteDifferences: rand_tangent
93
89
end
94
90
95
91
@testset " compsition of addition" begin
96
- x = Foo (1.5 , 2 , Foo (1.1 , 3 , [1.7 , 1.4 , 0.9 ]))
92
+ x = Bar (1.5 , 2 , Bar (1.1 , 3 , [1.7 , 1.4 , 0.9 ]))
97
93
@test x + rand_tangent (x) isa typeof (x)
98
94
@test x + (rand_tangent (x) + rand_tangent (x)) isa typeof (x)
99
95
end
0 commit comments