Skip to content

Commit

Permalink
Merge pull request #203 from JuliaDiff/mz/notangent
Browse files Browse the repository at this point in the history
Use `NoTangent()` instead of `nothing` to designate non-differentiability
  • Loading branch information
mzgubic committed Aug 6, 2021
2 parents e0f1171 + be9dbdb commit 011b4e2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRulesTestUtils"
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
version = "1.0.0"
version = "1.1.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
8 changes: 4 additions & 4 deletions src/finite_difference_calls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function _make_jvp_call(fdm, f, y, xs, ẋs, ignores)
f2 = _wrap_function(f, xs, ignores)

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

ignores = collect(ignores)
args = Any[nothing for _ in 1:length(xs)]
args = Any[NoTangent() for _ in 1:length(xs)]
all(ignores) && return (args...,)
sigargs = xs[.!ignores]
arginds = (1:length(xs))[.!ignores]
Expand All @@ -66,7 +66,7 @@ Return a new version of `f`, `fnew`, that ignores some of the arguments `xs`.
- `f`: The function to be wrapped.
- `xs`: Inputs to `f`, such that `y = f(xs...)`.
- `ignores`: Collection of `Bool`s, the same length as `xs`.
If `ignores[i] === true`, then `xs[i]` is ignored; `∂xs[i] === nothing`.
If `ignores[i] === true`, then `xs[i]` is ignored; `∂xs[i] === NoTangent()`.
"""
function _wrap_function(f, xs, ignores)
function fnew(sigargs...)
Expand Down
2 changes: 1 addition & 1 deletion src/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function test_rrule(
accum_cotangents, ad_cotangents, fd_cotangents
)
if accum_cotangent isa NoTangent # then we marked this argument as not differentiable
@assert fd_cotangent === nothing # this is how `_make_j′vp_call` works
@assert fd_cotangent === NoTangent()
ad_cotangent isa ZeroTangent && error(
"The pullback in the rrule should use NoTangent()" *
" rather than ZeroTangent() for non-perturbable arguments.",
Expand Down

2 comments on commit 011b4e2

@mzgubic
Copy link
Member Author

@mzgubic mzgubic commented on 011b4e2 Aug 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/42297

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.0 -m "<description of version>" 011b4e2a47ee92734b8dfbd4067b8ff184bb54cb
git push origin v1.1.0

Please sign in to comment.