@@ -540,8 +540,29 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
540540 @test dual_isapprox (f (PRIMAL, PRIMAL2, FDNUM3), Dual {TestTag()} (f (PRIMAL, PRIMAL2, PRIMAL3), PARTIALS3))
541541 end
542542
543+ # Functions in Specialfunctions that return tuples and
544+ # therefore are not supported by DiffRules
543545 @test dual_isapprox (logabsgamma (FDNUM)[1 ], loggamma (abs (FDNUM)))
544546 @test dual_isapprox (logabsgamma (FDNUM)[2 ], sign (gamma (FDNUM)))
547+
548+ a = rand (float (V))
549+ fdnum = Dual {TestTag()} (1 + PRIMAL, PARTIALS) # 1 + PRIMAL avoids issues with finite differencing close to 0
550+ for ind in ((), (0 ,), (1 ,), (2 ,))
551+ # Only test if primal method exists
552+ # (e.g., older versions of SpecialFunctions don't define `gamma_inc(a, x)` but only `gamma_inc(a, x, ind)`
553+ hasmethod (gamma_inc, typeof ((a, 1 + PRIMAL, ind... ))) || continue
554+
555+ pq = gamma_inc (a, fdnum, ind... )
556+ @test pq isa Tuple{Dual{TestTag ()},Dual{TestTag ()}}
557+ # We have to adjust tolerances if lower accuracy is requested
558+ # Therefore we don't use `dual_isapprox`
559+ tol = V === Float32 ? 5f-4 : 1e-6
560+ tol = tol^ (one (tol) / 2 ^ (isempty (ind) ? 0 : first (ind)))
561+ for i in 1 : 2
562+ @test value (pq[i]) ≈ gamma_inc (a, 1 + PRIMAL, ind... )[i] rtol= tol
563+ @test partials (pq[i]) ≈ PARTIALS * Calculus. derivative (x -> gamma_inc (a, x, ind... )[i], 1 + PRIMAL) rtol= tol
564+ end
565+ end
545566end
546567
547568@testset " Exponentiation of zero" begin
0 commit comments