Skip to content

Commit 0d6593e

Browse files
committed
test projection in scalar_rule
1 parent fbd3e7d commit 0d6593e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/rule_definition_tools.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ end
237237
@testisa Tangent{Tuple{Irrational{}, Float64}, Tuple{Float32, Float32}}
238238
end
239239

240+
@testset "@scalar_rule projection" begin
241+
make_imaginary(x) = im*x
242+
@scalar_rule make_imaginary(x) im
243+
244+
# note: the === will make sure that these are Float64, not ComplexF64
245+
@test (NoTangent(), 1.0) === rrule(make_imaginary, 2.0)[2](1.0*im)
246+
@test (NoTangent(), 0.0) === rrule(make_imaginary, 2.0)[2](1.0)
247+
248+
@test (NoTangent(), 1.0+0.0im) === rrule(make_imaginary, 2.0im)[2](1.0*im)
249+
@test (NoTangent(), 0.0-1.0im) === rrule(make_imaginary, 2.0im)[2](1.0)
250+
end
251+
240252
@testset "Regression tests against #276 and #265" begin
241253
# https://github.com/JuliaDiff/ChainRulesCore.jl/pull/276
242254
# https://github.com/JuliaDiff/ChainRulesCore.jl/pull/265

0 commit comments

Comments
 (0)