Skip to content

Commit

Permalink
Convert irrational manually with oftype
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Sep 24, 2021
1 parent 02d5e64 commit 661ee35
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ChainRulesCore.@scalar_rule(erf(x, y), (- (2 * exp(-x^2)) / sqrtπ, (2 * exp(-y^
ChainRulesCore.@scalar_rule(erfc(x), - (2 * exp(-x^2)) / sqrtπ)
ChainRulesCore.@scalar_rule(logerfc(x), - (2 * exp(-x^2 - Ω)) / sqrtπ)
ChainRulesCore.@scalar_rule(erfcinv(x), - (sqrtπ * (exp^2) / 2)))
ChainRulesCore.@scalar_rule(erfcx(x), 2 * x * Ω - 2 / sqrtπ)
ChainRulesCore.@scalar_rule(erfcx(x), 2 * (x * Ω - inv(oftype(Ω, sqrtπ))))
ChainRulesCore.@scalar_rule(logerfcx(x), 2 * (x - exp(-Ω) / sqrtπ))
ChainRulesCore.@scalar_rule(erfi(x), (2 * exp(x^2)) / sqrtπ)
ChainRulesCore.@scalar_rule(erfinv(x), sqrtπ * (exp^2) / 2))
Expand Down
10 changes: 1 addition & 9 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
# https://github.com/JuliaMath/SpecialFunctions.jl/issues/307
@testset "promotions" begin
# one argument
for f in (erf, erfc, logerfc, erfcinv, logerfcx, erfi, erfinv, sinint)
for f in (erf, erfc, logerfc, erfcinv, erfcx, logerfcx, erfi, erfinv, sinint)
_, ẏ = frule((NoTangent(), 1f0), f, 1f0)
@testisa Float32
_, back = rrule(f, 1f0)
Expand All @@ -161,13 +161,5 @@
_, back = rrule(erf, 1f0, 1f0)
_, x̄ = back(1f0)
@testisa Float32

# currently broken, can be fixed if `invsqrtπ` is available:
# https://github.com/JuliaMath/IrrationalConstants.jl/pull/8#issuecomment-925828753
_, ẏ = frule((NoTangent(), 1f0), erfcx, 1f0)
@test_brokenisa Float32
_, back = rrule(erfcx, 1f0)
_, x̄ = back(1f0)
@testisa Float32
end
end

0 comments on commit 661ee35

Please sign in to comment.