@@ -29,12 +29,14 @@ J_sparsity = Symbolics.jacobian_sparsity(fdiff, similar(x), x);
29
29
SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection (jac_prototype = J_sparsity),
30
30
SymbolicsSparsityDetection (), NoSparsityDetection ()]
31
31
32
- @testset " Sparsity Detection: $(nameof (typeof (sd))) " for sd in SPARSITY_DETECTION_ALGS
33
- @info " Sparsity Detection: $(nameof (typeof (sd))) "
34
- @info " Out of Place Function"
35
- @testset " sparse_jacobian: Out of Place" begin
36
- for difftype in (AutoSparseZygote (), AutoZygote (), AutoSparseForwardDiff (),
37
- AutoForwardDiff (), AutoSparseFiniteDiff (), AutoFiniteDiff ())
32
+ @testset " High-Level API" begin
33
+ @testset " Sparsity Detection: $(nameof (typeof (sd))) " for sd in SPARSITY_DETECTION_ALGS
34
+ @info " Sparsity Detection: $(nameof (typeof (sd))) "
35
+ @info " Out of Place Function"
36
+
37
+ @testset " sparse_jacobian $(nameof (typeof (difftype))) : Out of Place" for difftype in (AutoSparseZygote (),
38
+ AutoZygote (), AutoSparseForwardDiff (), AutoForwardDiff (),
39
+ AutoSparseFiniteDiff (), AutoFiniteDiff ())
38
40
@testset " Cache & Reuse" begin
39
41
cache = sparse_jacobian_cache (difftype, sd, fdiff, x)
40
42
J = SparseDiffTools. __init_𝒥 (cache)
@@ -50,7 +52,10 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
50
52
J = sparse_jacobian (difftype, cache, fdiff, x)
51
53
52
54
@test J ≈ J_true
53
- # @inferred sparse_jacobian(difftype, cache, fdiff, x)
55
+
56
+ if ! (difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff)
57
+ @inferred sparse_jacobian (difftype, cache, fdiff, x)
58
+ end
54
59
55
60
t₂ = @elapsed sparse_jacobian (difftype, cache, fdiff, x)
56
61
@info " $(nameof (typeof (difftype))) () `sparse_jacobian` (with matrix allocation) time: $(t₂) s"
@@ -60,7 +65,9 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
60
65
J = sparse_jacobian (difftype, sd, fdiff, x)
61
66
62
67
@test J ≈ J_true
63
- # @inferred sparse_jacobian(difftype, sd, fdiff, x)
68
+ if ! (difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff)
69
+ @inferred sparse_jacobian (difftype, sd, fdiff, x)
70
+ end
64
71
65
72
t₁ = @elapsed sparse_jacobian (difftype, sd, fdiff, x)
66
73
@info " $(nameof (typeof (difftype))) () `sparse_jacobian` (complete) time: $(t₁) s"
@@ -77,14 +84,14 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
77
84
@info " $(nameof (typeof (difftype))) () `sparse_jacobian!` (with matrix coloring) time: $(t₂) s"
78
85
end
79
86
end
80
- end
81
87
82
- @info " Inplace Place Function"
83
- @testset " sparse_jacobian: In place " begin
84
- for difftype in (AutoSparseForwardDiff (), AutoForwardDiff (), AutoSparseFiniteDiff (),
85
- AutoFiniteDiff ())
88
+ @info " Inplace Place Function"
89
+
90
+ @testset " sparse_jacobian $( nameof ( typeof (difftype))) : In place " for difftype in (AutoSparseForwardDiff (),
91
+ AutoForwardDiff (), AutoSparseFiniteDiff (), AutoFiniteDiff ())
86
92
y = similar (x)
87
93
cache = sparse_jacobian_cache (difftype, sd, fdiff, y, x)
94
+
88
95
@testset " Cache & Reuse" begin
89
96
J = SparseDiffTools. __init_𝒥 (cache)
90
97
sparse_jacobian! (J, difftype, cache, fdiff, y, x)
@@ -98,7 +105,9 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
98
105
J = sparse_jacobian (difftype, cache, fdiff, y, x)
99
106
100
107
@test J ≈ J_true
101
- # @inferred sparse_jacobian(difftype, cache, fdiff, y, x)
108
+ if ! (difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff)
109
+ @inferred sparse_jacobian (difftype, cache, fdiff, y, x)
110
+ end
102
111
103
112
t₂ = @elapsed sparse_jacobian (difftype, cache, fdiff, y, x)
104
113
@info " $(nameof (typeof (difftype))) () `sparse_jacobian` (with jacobian allocation) time: $(t₂) s"
@@ -108,7 +117,9 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
108
117
J = sparse_jacobian (difftype, sd, fdiff, y, x)
109
118
110
119
@test J ≈ J_true
111
- # @inferred sparse_jacobian(difftype, sd, fdiff, y, x)
120
+ if ! (difftype isa AutoSparseForwardDiff || difftype isa AutoForwardDiff)
121
+ @inferred sparse_jacobian (difftype, sd, fdiff, y, x)
122
+ end
112
123
113
124
t₁ = @elapsed sparse_jacobian (difftype, sd, fdiff, y, x)
114
125
@info " $(nameof (typeof (difftype))) () `sparse_jacobian` (complete) time: $(t₁) s"
@@ -125,7 +136,8 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
125
136
end
126
137
end
127
138
128
- for difftype in (AutoSparseZygote (), AutoZygote ())
139
+ @testset " sparse_jacobian $(nameof (typeof (difftype))) : In place" for difftype in (AutoSparseZygote (),
140
+ AutoZygote ())
129
141
y = similar (x)
130
142
cache = sparse_jacobian_cache (difftype, sd, fdiff, y, x)
131
143
J = SparseDiffTools. __init_𝒥 (cache)
@@ -141,4 +153,4 @@ SPARSITY_DETECTION_ALGS = [JacPrototypeSparsityDetection(jac_prototype = J_spars
141
153
end
142
154
end
143
155
end
144
- end
156
+ end
0 commit comments