-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
29 additions
and
3 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 |
---|---|---|
|
@@ -3,8 +3,9 @@ uuid = "944e5dbc-7108-4f31-a215-df58b8009117" | |
authors = ["Mitja Devetak <[email protected]>"] | ||
version = "0.1.0" | ||
|
||
|
||
[deps] | ||
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" | ||
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ function heaviside(x) | |
return x > zero(T) ? one(T) : zero(T) | ||
end | ||
|
||
|
||
include("./ignore_gradient.jl") | ||
|
||
|
||
|
||
|
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,6 @@ | ||
export ignore_gradient | ||
|
||
using ForwardDiff, ChainRulesCore | ||
|
||
ignore_gradient(x) = ChainRulesCore.@ignore_derivatives x | ||
ignore_gradient(x::ForwardDiff.Dual) = typeof(x)(x.value) |
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,17 @@ | ||
using DiscoDiff | ||
using Test | ||
using ForwardDiff, Zygote | ||
|
||
@testset "ignore gradient" begin | ||
|
||
function f(x) | ||
|
||
return 3x + x^2 - ignore_gradient(x^2) | ||
|
||
end | ||
|
||
x = 2.0 | ||
@test isapprox(ForwardDiff.derivative(f, x), 3 + 2x, atol = 1e-8) | ||
@test isapprox(Zygote.gradient(f, x)[1], 3 + 2x, atol = 1e-8) | ||
|
||
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