@@ -67,11 +67,11 @@ function test_scalar(f, z; rtol=1e-9, atol=1e-9, fdm=_fdm, fkwargs=NamedTuple(),
6767end
6868
6969"""
70- test_frule(f, inputs. ..; kwargs...)
70+ test_frule(f, args ..; kwargs...)
7171
7272# Arguments
7373- `f`: Function for which the `frule` should be tested.
74- - `inputs ` either the primal inputs `x`, or primals and their tangents: `x ⊢ ẋ`
74+ - `args ` either the primal args `x`, or primals and their tangents: `x ⊢ ẋ`
7575 - `x`: input at which to evaluate `f` (should generally be set to an arbitary point in the domain).
7676 - `ẋ`: differential w.r.t. `x`, will be generated automatically if not provided
7777 Non-differentiable arguments, such as indices, should have `ẋ` set as `NoTangent()`.
8787"""
8888function test_frule (
8989 f,
90- inputs ... ;
90+ args ... ;
9191 output_tangent= Auto (),
9292 fdm= _fdm,
9393 check_inferred:: Bool = true ,
@@ -99,18 +99,18 @@ function test_frule(
9999 # To simplify some of the calls we make later lets group the kwargs for reuse
100100 isapprox_kwargs = (; rtol= rtol, atol= atol, kwargs... )
101101
102- @testset " test_frule: $f on $(_string_typeof (inputs )) " begin
102+ @testset " test_frule: $f on $(_string_typeof (args )) " begin
103103 _ensure_not_running_on_functor (f, " test_frule" )
104104
105- xẋs = auto_primal_and_tangent .(inputs )
105+ xẋs = auto_primal_and_tangent .(args )
106106 xs = primal .(xẋs)
107107 ẋs = tangent .(xẋs)
108108 if check_inferred && _is_inferrable (f, deepcopy (xs)... ; deepcopy (fkwargs)... )
109109 _test_inferred (frule, (NoTangent (), deepcopy (ẋs)... ), f, deepcopy (xs)... ; deepcopy (fkwargs)... )
110110 end
111111 res = frule ((NoTangent (), deepcopy (ẋs)... ), f, deepcopy (xs)... ; deepcopy (fkwargs)... )
112112 res === nothing && throw (MethodError (frule, typeof ((f, xs... ))))
113- res isa Tuple || error ( " The frule should return (y, ∂y), not $res ." )
113+ @test_msg " The frule should return (y, ∂y), not $res ." res isa Tuple{Any,Any}
114114 Ω_ad, dΩ_ad = res
115115 Ω = f (deepcopy (xs)... ; deepcopy (fkwargs)... )
116116 test_approx (Ω_ad, Ω; isapprox_kwargs... )
@@ -135,11 +135,11 @@ function test_frule(
135135end
136136
137137"""
138- test_rrule(f, inputs ...; kwargs...)
138+ test_rrule(f, args ...; kwargs...)
139139
140140# Arguments
141141- `f`: Function to which rule should be applied.
142- - `inputs ` either the primal inputs `x`, or primals and their tangents: `x ⊢ ẋ`
142+ - `args ` either the primal args `x`, or primals and their tangents: `x ⊢ ẋ`
143143 - `x`: input at which to evaluate `f` (should generally be set to an arbitary point in the domain).
144144 - `x̄`: currently accumulated cotangent, will be generated automatically if not provided
145145 Non-differentiable arguments, such as indices, should have `x̄` set as `NoTangent()`.
155155"""
156156function test_rrule (
157157 f,
158- inputs ... ;
158+ args ... ;
159159 output_tangent= Auto (),
160160 fdm= _fdm,
161161 check_inferred:: Bool = true ,
@@ -167,11 +167,11 @@ function test_rrule(
167167 # To simplify some of the calls we make later lets group the kwargs for reuse
168168 isapprox_kwargs = (; rtol= rtol, atol= atol, kwargs... )
169169
170- @testset " test_rrule: $f on $(_string_typeof (inputs )) " begin
170+ @testset " test_rrule: $f on $(_string_typeof (args )) " begin
171171 _ensure_not_running_on_functor (f, " test_rrule" )
172172
173173 # Check correctness of evaluation.
174- xx̄s = auto_primal_and_tangent .(inputs )
174+ xx̄s = auto_primal_and_tangent .(args )
175175 xs = primal .(xx̄s)
176176 accumulated_x̄ = tangent .(xx̄s)
177177 if check_inferred && _is_inferrable (f, xs... ; fkwargs... )
@@ -191,6 +191,8 @@ function test_rrule(
191191 ∂self = ∂s[1 ]
192192 x̄s_ad = ∂s[2 : end ]
193193 @test ∂self === NoTangent () # No internal fields
194+ msg = " The pullback should return 1 cotangent for each primal input."
195+ @test_msg msg length (x̄s_ad) == length (args)
194196
195197 # Correctness testing via finite differencing.
196198 # TODO : remove Nothing when https://github.com/JuliaDiff/ChainRulesTestUtils.jl/issues/113
0 commit comments