Skip to content

Commit 34bfe31

Browse files
committed
change gamma.c function to support np.inf special cases
1 parent 1091b44 commit 34bfe31

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pytensor/scalar/c_code/gamma.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ DEVICE double GammaP (double n, double x)
218218
{ /* --- regularized Gamma function P */
219219
if ((n <= 0) || (x < 0)) return NPY_NAN; /* check the function arguments */
220220
if (x <= 0) return 0; /* treat x = 0 as a special case */
221+
if (isinf(n)) {
222+
if (isinf(x)) return NPY_NAN;
223+
return 0;
224+
}
225+
if (isinf(x)) return 1;
221226
if (x < n+1) return _series(n, x) *exp(n *log(x) -x -logGamma(n));
222227
return 1 -_cfrac(n, x) *exp(n *log(x) -x -logGamma(n));
223228
} /* GammaP() */
@@ -228,6 +233,11 @@ DEVICE double GammaQ (double n, double x)
228233
{ /* --- regularized Gamma function Q */
229234
if ((n <= 0) || (x < 0)) return NPY_NAN; /* check the function arguments */
230235
if (x <= 0) return 1; /* treat x = 0 as a special case */
236+
if (isinf(n)) {
237+
if (isinf(x)) return NPY_NAN;
238+
return 1;
239+
}
240+
if (isinf(x)) return 0;
231241
if (x < n+1) return 1 -_series(n, x) *exp(n *log(x) -x -logGamma(n));
232242
return _cfrac(n, x) *exp(n *log(x) -x -logGamma(n));
233243
} /* GammaQ() */

0 commit comments

Comments
 (0)