-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ForwardDiff package extension (#200)
- Loading branch information
Showing
7 changed files
with
54 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module SparseConnectivityTracerForwardDiffExt | ||
|
||
if isdefined(Base, :get_extension) | ||
import SparseConnectivityTracer as SCT | ||
using ForwardDiff: ForwardDiff | ||
else | ||
import ..SparseConnectivityTracer as SCT | ||
using ..ForwardDiff: ForwardDiff | ||
end | ||
|
||
# Overload 2-to-1 functions on ForwardDiff.Dual | ||
eval(SCT.generate_code_2_to_1_typed(:Base, SCT.ops_2_to_1, ForwardDiff.Dual)) | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using SparseConnectivityTracer | ||
using ForwardDiff: ForwardDiff | ||
|
||
using Test | ||
|
||
d = ForwardDiff.Dual{ForwardDiff.Tag{*,Float64}}(1.2, 3.4) | ||
@testset "$D" for D in (TracerSparsityDetector, TracerLocalSparsityDetector) | ||
detector = D() | ||
# Testing on multiplication ensures that methods from Base have been overloaded, | ||
# Since this would otherwise throw an ambiguity error: | ||
# https://github.com/adrhill/SparseConnectivityTracer.jl/issues/196 | ||
@testset "Jacobian" begin | ||
@test jacobian_sparsity(x -> x * d, 1.0, detector) ≈ [1;;] | ||
@test jacobian_sparsity(x -> d * x, 1.0, detector) ≈ [1;;] | ||
end | ||
@testset "Hessian" begin | ||
@test hessian_sparsity(x -> x * d, 1.0, detector) ≈ [0;;] | ||
@test hessian_sparsity(x -> d * x, 1.0, detector) ≈ [0;;] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters