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

Avoid NaN (co)tangents for sqrt(0) #599

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Test sqrt(0)
sethaxen committed Mar 11, 2022
commit e43c03bef8f6b50e1f6c7856d3b6597d966c56cb
13 changes: 13 additions & 0 deletions test/rulesets/Base/fastmath_able.jl
Original file line number Diff line number Diff line change
@@ -90,6 +90,19 @@ const FASTABLE_AST = quote
end
end

# https://github.com/JuliaDiff/ChainRules.jl/issues/576
@testset "sqrt(0)" begin
@testset for T in (Float64, ComplexF64)
z = zero(T)
@test frule((NoTangent(), z), sqrt, z)[2] === z
@test frule((NoTangent(), ZeroTangent()), sqrt, z)[2] === ZeroTangent()
@test !isfinite(frule((NoTangent(), one(z)), sqrt, z)[2])
@test rrule(sqrt, z)[2](z)[2] === z
@test rrule(sqrt, z)[2](ZeroTangent())[2] === ZeroTangent()
@test !isfinite(rrule(sqrt, z)[2](one(z))[2])
end
end

@testset "Unary complex functions" begin
for f (abs, abs2, conj), z (-4.1-0.02im, 6.4, 3 + im)
@testset "Unary complex functions f = $f, z = $z" begin