Skip to content

Commit 011b4e2

Browse files
authored
Merge pull request #203 from JuliaDiff/mz/notangent
Use `NoTangent()` instead of `nothing` to designate non-differentiability
2 parents e0f1171 + be9dbdb commit 011b4e2

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesTestUtils"
22
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
3-
version = "1.0.0"
3+
version = "1.1.0"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/finite_difference_calls.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function _make_jvp_call(fdm, f, y, xs, ẋs, ignores)
1919
f2 = _wrap_function(f, xs, ignores)
2020

2121
ignores = collect(ignores)
22-
all(ignores) && return ntuple(_ -> nothing, length(xs))
22+
all(ignores) && return ntuple(_ -> NoTangent(), length(xs))
2323
sigargs = zip(xs[.!ignores], ẋs[.!ignores])
2424
return _maybe_fix_to_composite(y, jvp(fdm, f2, sigargs...))
2525
end
@@ -35,7 +35,7 @@ Call `FiniteDifferences.j′vp`, with the option to ignore certain `xs`.
3535
- `ȳ`: The adjoint w.r.t. output of `f`.
3636
- `xs`: Inputs to `f`, such that `y = f(xs...)`.
3737
- `ignores`: Collection of `Bool`s, the same length as `xs`.
38-
If `ignores[i] === true`, then `xs[i]` is ignored; `∂xs[i] === nothing`.
38+
If `ignores[i] === true`, then `xs[i]` is ignored; `∂xs[i] === NoTangent()`.
3939
4040
# Returns
4141
- `∂xs::Tuple`: Derivatives estimated by finite differencing.
@@ -44,7 +44,7 @@ function _make_j′vp_call(fdm, f, ȳ, xs, ignores)
4444
f2 = _wrap_function(f, xs, ignores)
4545

4646
ignores = collect(ignores)
47-
args = Any[nothing for _ in 1:length(xs)]
47+
args = Any[NoTangent() for _ in 1:length(xs)]
4848
all(ignores) && return (args...,)
4949
sigargs = xs[.!ignores]
5050
arginds = (1:length(xs))[.!ignores]
@@ -66,7 +66,7 @@ Return a new version of `f`, `fnew`, that ignores some of the arguments `xs`.
6666
- `f`: The function to be wrapped.
6767
- `xs`: Inputs to `f`, such that `y = f(xs...)`.
6868
- `ignores`: Collection of `Bool`s, the same length as `xs`.
69-
If `ignores[i] === true`, then `xs[i]` is ignored; `∂xs[i] === nothing`.
69+
If `ignores[i] === true`, then `xs[i]` is ignored; `∂xs[i] === NoTangent()`.
7070
"""
7171
function _wrap_function(f, xs, ignores)
7272
function fnew(sigargs...)

src/testers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function test_rrule(
225225
accum_cotangents, ad_cotangents, fd_cotangents
226226
)
227227
if accum_cotangent isa NoTangent # then we marked this argument as not differentiable
228-
@assert fd_cotangent === nothing # this is how `_make_j′vp_call` works
228+
@assert fd_cotangent === NoTangent()
229229
ad_cotangent isa ZeroTangent && error(
230230
"The pullback in the rrule should use NoTangent()" *
231231
" rather than ZeroTangent() for non-perturbable arguments.",

0 commit comments

Comments
 (0)