@@ -3,6 +3,9 @@ using ForwardDiff
33using Test
44using ForwardDiff: Dual, partials, value
55
6+ # Needed until https://github.com/JuliaDiff/ForwardDiff.jl/pull/732 is merged
7+ complexpartials (x, k) = partials (real (x), k) + im* partials (imag (x), k)
8+
69@testset " ForwardDiff extension tests" begin
710 x1 = Dual .(1 : 4.0 , 2 : 5 , 3 : 6 )
811
@@ -13,42 +16,42 @@ using ForwardDiff: Dual, partials, value
1316
1417 @testset " $f " for f in (fft, ifft, rfft, bfft)
1518 @test value .(f (x1)) == f (value .(x1))
16- @test partials .( real ( f (x1)), 1 ) + im * partials .( imag ( f (x1) ), 1 ) == f (partials .(x1, 1 ))
17- @test partials .( real ( f (x1)), 2 ) + im * partials .( imag ( f (x1) ), 2 ) == f (partials .(x1, 2 ))
19+ @test complexpartials .( f (x1), 1 ) == f (partials .(x1, 1 ))
20+ @test complexpartials .( f (x1), 2 ) == f (partials .(x1, 2 ))
1821 end
1922
2023 @test ifft (fft (x1)) ≈ x1
2124 @test irfft (rfft (x1), length (x1)) ≈ x1
2225 @test brfft (rfft (x1), length (x1)) ≈ 4 x1
2326
2427 f = x -> real (fft ([x; 0 ; 0 ])[1 ])
25- @test derivative (f,0.1 ) ≈ 1
28+ @test ForwardDiff . derivative (f,0.1 ) ≈ 1
2629
2730 r = x -> real (rfft ([x; 0 ; 0 ])[1 ])
28- @test derivative (r,0.1 ) ≈ 1
31+ @test ForwardDiff . derivative (r,0.1 ) ≈ 1
2932
3033
3134 n = 100
3235 θ = range (0 ,2 π; length= n+ 1 )[1 : end - 1 ]
3336 # emperical from Mathematical
34- @test derivative (ω -> fft (exp .(ω .* cos .(θ)))[1 ]/ n, 1 ) ≈ 0.565159103992485
37+ @test ForwardDiff . derivative (ω -> fft (exp .(ω .* cos .(θ)))[1 ]/ n, 1 ) ≈ 0.565159103992485
3538
3639 # c = x -> dct([x; 0; 0])[1]
3740 # @test derivative(c,0.1) ≈ 1
3841
3942 @testset " matrix" begin
4043 A = x1 * (1 : 10 )'
4144 @test value .(fft (A)) == fft (value .(A))
42- @test partials .(fft (A), 1 ) == fft (partials .(A, 1 ))
43- @test partials .(fft (A), 2 ) == fft (partials .(A, 2 ))
45+ @test complexpartials .(fft (A), 1 ) == fft (partials .(A, 1 ))
46+ @test complexpartials .(fft (A), 2 ) == fft (partials .(A, 2 ))
4447
4548 @test value .(fft (A, 1 )) == fft (value .(A), 1 )
46- @test partials .(fft (A, 1 ), 1 ) == fft (partials .(A, 1 ), 1 )
47- @test partials .(fft (A, 1 ), 2 ) == fft (partials .(A, 2 ), 1 )
49+ @test complexpartials .(fft (A, 1 ), 1 ) == fft (partials .(A, 1 ), 1 )
50+ @test complexpartials .(fft (A, 1 ), 2 ) == fft (partials .(A, 2 ), 1 )
4851
4952 @test value .(fft (A, 2 )) == fft (value .(A), 2 )
50- @test partials .(fft (A, 2 ), 1 ) == fft (partials .(A, 1 ), 2 )
51- @test partials .(fft (A, 2 ), 2 ) == fft (partials .(A, 2 ), 2 )
53+ @test complexpartials .(fft (A, 2 ), 1 ) == fft (partials .(A, 1 ), 2 )
54+ @test complexpartials .(fft (A, 2 ), 2 ) == fft (partials .(A, 2 ), 2 )
5255 end
5356
5457 c1 = complex .(x1)
0 commit comments