1
+ using DiffEqDiffTools, Base. Test
1
2
2
3
# TODO : add tests for GPUArrays
3
4
# TODO : add tests for DEDataArrays
@@ -162,9 +163,9 @@ x = rand(2)
162
163
fx = f (x)
163
164
df = zeros (2 )
164
165
df_ref = [2. , 2 * x[2 ]]
165
- forward_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:forward })
166
- central_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:central })
167
- complex_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:complex })
166
+ forward_cache = DiffEqDiffTools. GradientCache (df,x,Val{:forward })
167
+ central_cache = DiffEqDiffTools. GradientCache (df,x,Val{:central })
168
+ complex_cache = DiffEqDiffTools. GradientCache (df,x,Val{:complex })
168
169
169
170
@time @testset " Gradient of f:vector->scalar real-valued tests" begin
170
171
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }), df_ref) < 1e-4
@@ -185,8 +186,8 @@ x = x + im*x
185
186
fx = f (x)
186
187
df = zeros (x)
187
188
df_ref = conj ([2.0 + 2.0 * im, 2.0 * x[2 ]])
188
- forward_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:forward })
189
- central_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:central })
189
+ forward_cache = DiffEqDiffTools. GradientCache (df,x,Val{:forward })
190
+ central_cache = DiffEqDiffTools. GradientCache (df,x,Val{:central })
190
191
191
192
@time @testset " Gradient of f : C^N -> C tests" begin
192
193
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }), df_ref) < 1e-4
@@ -204,8 +205,8 @@ x = ones(2) * (1 + im)
204
205
fx = f (x)
205
206
df = zeros (x)
206
207
df_ref = 2 * x
207
- forward_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:forward })
208
- central_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:central })
208
+ forward_cache = DiffEqDiffTools. GradientCache (df,x,Val{:forward })
209
+ central_cache = DiffEqDiffTools. GradientCache (df,x,Val{:central })
209
210
210
211
@time @testset " Gradient of f : C^N -> R tests" begin
211
212
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }), df_ref) < 1e-4
@@ -223,8 +224,8 @@ x = ones(2)
223
224
fx = f (x)
224
225
df = zeros (eltype (fx), size (x))
225
226
df_ref = [2.0 , - im* 2 * x[2 ]]
226
- forward_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:forward },eltype (df))
227
- central_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:central },eltype (df))
227
+ forward_cache = DiffEqDiffTools. GradientCache (df,x,Val{:forward },eltype (df))
228
+ central_cache = DiffEqDiffTools. GradientCache (df,x,Val{:central },eltype (df))
228
229
229
230
@time @testset " Gradient of f : R^N -> C tests" begin
230
231
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }, eltype (df)), df_ref) < 1e-4
@@ -243,9 +244,10 @@ fx = zeros(2)
243
244
f (fx,x)
244
245
df = zeros (2 )
245
246
df_ref = [cos (x), - sin (x)]
246
- forward_cache = DiffEqDiffTools. GradientCache (df,x,fx,nothing ,nothing ,Val{:forward })
247
- central_cache = DiffEqDiffTools. GradientCache (df,x,fx,nothing ,nothing ,Val{:central })
248
- complex_cache = DiffEqDiffTools. GradientCache (df,x,fx,nothing ,nothing ,Val{:complex })
247
+ forward_cache = DiffEqDiffTools. GradientCache (df,x,Val{:forward })
248
+ central_cache = DiffEqDiffTools. GradientCache (df,x,Val{:central })
249
+ complex_cache = DiffEqDiffTools. GradientCache (df,x,Val{:complex })
250
+
249
251
250
252
@time @testset " Gradient of f:scalar->vector real-valued tests" begin
251
253
@test_broken err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }), df_ref) < 1e-4
@@ -268,8 +270,8 @@ fx = zeros(typeof(x), 2)
268
270
f (fx,x)
269
271
df = zeros (fx)
270
272
df_ref = [cos (x), - sin (x)]
271
- forward_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:forward })
272
- central_cache = DiffEqDiffTools. GradientCache (df,x,fx, nothing , nothing , Val{:central })
273
+ forward_cache = DiffEqDiffTools. GradientCache (df,x,Val{:forward })
274
+ central_cache = DiffEqDiffTools. GradientCache (df,x,Val{:central })
273
275
274
276
@time @testset " Gradient of f:vector->scalar complex-valued tests" begin
275
277
@test err_func (DiffEqDiffTools. finite_difference_gradient (f, x, Val{:forward }, eltype (x), Val{true }, fx), df_ref) < 1e-4
0 commit comments