1
+
2
+ # TODO : add tests for GPUArrays
3
+ # TODO : add tests for DEDataArrays
4
+
5
+
6
+ # Derivative tests
1
7
x = collect (linspace (- 2 π, 2 π, 100 ))
2
8
y = sin .(x)
3
9
df = zeros (100 )
@@ -9,9 +15,6 @@ complex_cache = DiffEqDiffTools.DerivativeCache(x, nothing, nothing, Val{:comple
9
15
10
16
err_func (a,b) = maximum (abs .(a- b))
11
17
12
- # TODO : add tests for GPUArrays
13
- # TODO : add tests for DEDataArrays
14
-
15
18
@time @testset " Derivative single point real-valued tests" begin
16
19
@test err_func (DiffEqDiffTools. finite_difference_derivative (sin, π/ 4 , Val{:forward }), √ 2 / 2 ) < 1e-4
17
20
@test err_func (DiffEqDiffTools. finite_difference_derivative (sin, π/ 4 , Val{:central }), √ 2 / 2 ) < 1e-8
85
88
@test err_func (DiffEqDiffTools. finite_difference_derivative! (df, f, x, central_cache), df_ref) < 1e-8
86
89
end
87
90
91
+ # Gradient tests
88
92
f (x) = 2 x[1 ] + x[2 ]^ 2
89
93
x = rand (2 )
90
94
fx = f (x)
91
95
df = zeros (2 )
92
96
df_ref = [2. , 2 * x[2 ]]
93
97
forward_cache = DiffEqDiffTools. GradientCache (df,x,fx,nothing ,nothing ,Val{:forward },Val{:Real })
94
98
central_cache = DiffEqDiffTools. GradientCache (df,x,fx,nothing ,nothing ,Val{:central },Val{:Real })
95
- # complex_cache = DiffEqDiffTools.GradientCache(df,x,fx,nothing,nothing,Val{:complex},Val{:Real})
99
+ complex_cache = DiffEqDiffTools. GradientCache (df,x,fx,nothing ,nothing ,Val{:complex },Val{:Real })
96
100
97
101
@time @testset " Gradient of f:R^n->R real-valued tests" begin
98
102
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }), df_ref) < 1e-4
99
103
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:central }), df_ref) < 1e-8
100
- # @test err_func(DiffEqDiffTools.finite_difference_gradient(f, x, Val{:complex}), df_ref) < 1e-15
104
+ @test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:complex }), df_ref) < 1e-15
101
105
102
106
@test err_func (DiffEqDiffTools. finite_difference_gradient! (df, f, x, Val{:forward }), df_ref) < 1e-4
103
107
@test err_func (DiffEqDiffTools. finite_difference_gradient! (df, f, x, Val{:central }), df_ref) < 1e-8
104
- # @test err_func(DiffEqDiffTools.finite_difference_gradient!(df, f, x, Val{:complex}), df_ref) < 1e-15
108
+ @test err_func (DiffEqDiffTools. finite_difference_gradient! (df, f, x, Val{:complex }), df_ref) < 1e-15
105
109
106
110
@test err_func (DiffEqDiffTools. finite_difference_gradient! (df, f, x, forward_cache), df_ref) < 1e-4
107
111
@test err_func (DiffEqDiffTools. finite_difference_gradient! (df, f, x, central_cache), df_ref) < 1e-8
108
- # @test err_func(DiffEqDiffTools.finite_difference_gradient!(df, f, x, complex_cache), df_ref) < 1e-15
112
+ @test err_func (DiffEqDiffTools. finite_difference_gradient! (df, f, x, complex_cache), df_ref) < 1e-15
113
+ end
114
+
115
+ @time @testset " Gradient of f:R^n->R complex-valued tests" begin
116
+ # TODO
109
117
end
110
118
119
+ @time @testset " Gradient of f:R->R^n real-valued tests" begin
120
+ # TODO
121
+ end
122
+
123
+ @time @testset " Gradient of f:R->R^n complex-valued tests" begin
124
+ # TODO
125
+ end
111
126
127
+ # Jacobian tests
112
128
function f (fvec,x)
113
129
fvec[1 ] = (x[1 ]+ 3 )* (x[2 ]^ 3 - 7 )+ 18
114
130
fvec[2 ] = sin (x[2 ]* exp (x[1 ])- 1 )
0 commit comments