Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that if only one adjoint exists, it is not thunked #53

Merged
merged 4 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "0.4.3"
version = "0.5.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
10 changes: 9 additions & 1 deletion src/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ function rrule_test(f, ȳ, xx̄s::Tuple{Any, Any}...; rtol=1e-9, atol=1e-9, fdm
x̄s_ad = ∂s[2:end]
@test ∂self === NO_FIELDS # No internal fields

x̄s_is_dne = x̄s .== nothing
# Correctness testing via finite differencing.
x̄s_fd = _make_fdm_call(fdm, (xs...) -> f(xs...; fkwargs...), ȳ, xs, x̄s .== nothing)
x̄s_fd = _make_fdm_call(fdm, (xs...) -> f(xs...; fkwargs...), ȳ, xs, x̄s_is_dne)
for (x̄_ad, x̄_fd) in zip(x̄s_ad, x̄s_fd)
if x̄_fd === nothing
# The way we've structured the above, this tests the propagator is returning a DoesNotExist
Expand All @@ -202,4 +203,11 @@ function rrule_test(f, ȳ, xx̄s::Tuple{Any, Any}...; rtol=1e-9, atol=1e-9, fdm
@test isapprox(x̄_ad, x̄_fd; rtol=rtol, atol=atol, kwargs...)
end
end

if count(!, x̄s_is_dne) == 1
# for functions with pullbacks that only produce a single non-DNE adjoint, that
# single adjoint should not be `Thunk`ed. InplaceableThunk is fine.
i = findfirst(!, x̄s_is_dne)
@test !(isa(x̄s_ad[i], Thunk))
end
end
5 changes: 1 addition & 4 deletions test/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ primalapprox(x) = x
# define rrule using ChainRulesCore's v0.9.0 convention, conjugating the derivative
# in the rrule
function ChainRulesCore.rrule(::typeof(sinconj), x)
# usually we would not thunk for a single output, because it will of course be
# used, but we do here to ensure that test_scalar works even if a scalar rrule
# thunks
sinconj_pullback(ΔΩ) = (NO_FIELDS, @thunk(conj(cos(x)) * ΔΩ))
sinconj_pullback(ΔΩ) = (NO_FIELDS, conj(cos(x)) * ΔΩ)
return sin(x), sinconj_pullback
end

Expand Down