From 78c73afd9a21593daf54f61c7d0db67130cf29e1 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Thu, 19 May 2022 01:56:50 +0200 Subject: [PATCH] Add definition for `logabsgamma` (#585) * Add definition for `logabsgamma` * Update test/DualTest.jl Co-authored-by: Frames Catherine White * Update Project.toml Co-authored-by: Frames Catherine White --- Project.toml | 2 +- src/dual.jl | 9 +++++++++ test/DualTest.jl | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index cb0abdb0..2930dc3b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ForwardDiff" uuid = "f6369f11-7733-5829-9624-2563aa707210" -version = "0.10.29" +version = "0.10.30" [deps] CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950" diff --git a/src/dual.jl b/src/dual.jl index 2594770e..8e99c9fe 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -755,6 +755,15 @@ function LinearAlgebra.eigen(A::SymTridiagonal{<:Dual{Tg,T,N}}) where {Tg,T<:Rea Eigen(λ,Dual{Tg}.(Q, tuple.(parts...))) end +# SpecialFunctions.logabsgamma # +# Derivative is not defined in DiffRules # +#----------------------------------------# + +function SpecialFunctions.logabsgamma(d::Dual{T,<:Real}) where {T} + x = value(d) + y, s = SpecialFunctions.logabsgamma(x) + return (Dual{T}(y, SpecialFunctions.digamma(x) * partials(d)), s) +end ################### # Pretty Printing # diff --git a/test/DualTest.jl b/test/DualTest.jl index fd5ac210..66a1866a 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -539,6 +539,9 @@ for N in (0,3), M in (0,4), V in (Int, Float32) @test dual_isapprox(f(FDNUM, PRIMAL2, PRIMAL3), Dual{TestTag()}(f(PRIMAL, PRIMAL2, PRIMAL3), PRIMAL2*PARTIALS)) @test dual_isapprox(f(PRIMAL, PRIMAL2, FDNUM3), Dual{TestTag()}(f(PRIMAL, PRIMAL2, PRIMAL3), PARTIALS3)) end + + @test dual_isapprox(logabsgamma(FDNUM)[1], loggamma(abs(FDNUM))) + @test dual_isapprox(logabsgamma(FDNUM)[2], sign(gamma(FDNUM))) end @testset "Exponentiation of zero" begin