# SpecialFunctions + Turing, AD support for quantile function of Gamma distribution gamma\_inv\_cdf

**URL:** https://discourse.julialang.org/t/specialfunctions-turing-ad-support-for-quantile-function-of-gamma-distribution-gamma-inv-cdf/113663
**Category:** General Usage
**Tags:** turing, distributions, specialfunctions
**Created:** [April 30, 2024, 5:14pm UTC](https://discourse.julialang.org/t/specialfunctions-turing-ad-support-for-quantile-function-of-gamma-distribution-gamma-inv-cdf/113663 "2024-04-30T17:14:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mleprovost](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mleprovost/32/7166_2.png) [@mleprovost](https://discourse.julialang.org/u/mleprovost)
#### Post date: [April 30, 2024, 5:14pm UTC](https://discourse.julialang.org/t/specialfunctions-turing-ad-support-for-quantile-function-of-gamma-distribution-gamma-inv-cdf/113663/1 "2024-04-30T17:14:39Z")

</div>

Hello,

I would like to use AD in Turing.jl to differentiate a custom density that involves the inverse cdf (i.e., quantile function) of a Gamma distribution.  
Unfortunately, the quantile function of the Gamma distribution defined in Distributions.jl does not support AD.  
The issue boils down to perform AD for the routine `gamma_inc_inv` from SpecialFunctions ([https://github.com/JuliaMath/SpecialFunctions.jl/blob/master/src/gamma\_inc.jl:](https://github.com/JuliaMath/SpecialFunctions.jl/blob/master/src/gamma_inc.jl:)) The function `gamma_inc_inv` only supports `Float64` input arguments.

```julia
using ForwardDiff
using SpecialFunctions
ForwardDiff.derivative(x -> gamma_inc_inv(x, 0.1, 0.9), 0.1)

```

Output:

```julia
MethodError: no method matching __gamma_inc_inv(::ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Float64}, Float64, 1}, ::ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Float64}, Float64, 1}, ::Bool)

Closest candidates are:
  __gamma_inc_inv(::Float64, ::Float64, ::Bool)
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/QH8rV/src/gamma_inc.jl:1012
  __gamma_inc_inv(::T, ::T, ::Bool) where T<:Union{Float16, Float32}
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/QH8rV/src/gamma_inc.jl:1089

Stacktrace:
 [1] _gamma_inc_inv
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/QH8rV/src/gamma_inc.jl:1009 [inlined]
 [2] gamma_inc_inv(a::ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Float64}, Float64, 1}, p::Float64, q::Float64)
   @ SpecialFunctions ~/.julia/packages/SpecialFunctions/QH8rV/src/gamma_inc.jl:991
 [3] (::var"#3#4")(x::ForwardDiff.Dual{ForwardDiff.Tag{var"#3#4", Float64}, Float64, 1})
   @ Main ./In[7]:1
 [4] derivative(f::var"#3#4", x::Float64)
   @ ForwardDiff ~/.julia/packages/ForwardDiff/PcZ48/src/derivative.jl:14
 [5] top-level scope
   @ In[7]:1

```
