File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using ForwardDiff
22
3+ using LinearAlgebra: diagm, I
4+
35@testset " test Julia function" begin
4- @vector x
6+ @matrix A B C
7+ @vector x y
58
69 x̂ = [
7- 0.0552
10+ 0.055
811 0.395
912 0.821
10- 0.558
11- 0.048
12- 0.144
13- 0.519
14- 0.376
15- 0.264
16- 0.001
13+ ]
14+
15+ ŷ = [
16+ 0.442
17+ 0.630
18+ 0.176
19+ ]
20+
21+ Â = [
22+ 0.023 0.136 0.181
23+ 0.443 0.132 0.576
24+ 0.786 0.198 0.583
25+ ]
26+
27+ B̂ = [
28+ 0.570 0.987 0.124
29+ 0.855 0.400 0.196
30+ 0.111 0.469 0.406
31+ ]
32+
33+ Ĉ = [
34+ 0.884 0.947 0.401
35+ 0.999 0.623 0.473
36+ 0.415 0.483 0.969
1737 ]
1838
1939 @testset " gradient of x'*x" begin
@@ -33,4 +53,17 @@ using ForwardDiff
3353
3454 @test jgrad (x̂) ≈ ForwardDiff. gradient (x -> cos (tr (x * x' )), x̂)
3555 end
56+
57+ @testset " jacobian of sin(A * x + y)" begin
58+ jgrad = eval (to_std (jacobian (sin (A * x + y), x); format = dc. Julia ()))
59+
60+ @test jgrad (Â, x̂, ŷ) ≈ ForwardDiff. jacobian (x -> sin .(Â * x + ŷ), x̂)
61+ end
62+
63+ @testset " jacobian of (A .* B) * C * x)' * x * x" begin
64+ jgrad = eval (to_std (jacobian (((A .* B) * C * x)' * x * x, x); format = dc. Julia ()))
65+
66+ @test jgrad (x̂, Ĉ, Â, B̂) ≈
67+ ForwardDiff. jacobian (x -> ((Â .* B̂) * Ĉ * x)' * x * x, x̂)
68+ end
3669end
You can’t perform that action at this time.
0 commit comments