calc_igammac Class — pytorch Architecture
Architecture documentation for the calc_igammac class in Math.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/Math.h lines 1063–1141
template <typename scalar_t>
inline scalar_t calc_igammac(scalar_t a, scalar_t x) {
/* the calculation of the regularized upper incomplete gamma function
* is done differently based on the values of a and x:
* - if x and/or a is at the boundary of defined region, then assign the
* result at the boundary
* - if a is large and a ~ x, then using Uniform Asymptotic Expansions for
* Large Parameter (see DLMF 8.12.4 [igam1])
* - if x > 1.1 and x < a, using the subtraction from the regularized lower
* incomplete gamma
* - otherwise, calculate the series from [igam2] eq (5)
*/
scalar_t absxma_a;
static scalar_t SMALL = 20.0;
static scalar_t LARGE = 200.0;
static scalar_t SMALLRATIO = 0.3;
static scalar_t LARGERATIO = 4.5;
// note that in SciPy, a and x are non-negative, with exclusive 0s (i.e.,
// at most 1 of them can be 0), where igammac(0, x) = 0.0 iff x > 0.
if ((x < 0) || (a < 0)) {
// out of defined-region of the function
return std::numeric_limits<scalar_t>::quiet_NaN();
}
else if (a == 0) {
if (x > 0) {
return 0.0;
}
else {
return std::numeric_limits<scalar_t>::quiet_NaN();
}
}
else if (x == 0) {
return 1.0;
}
else if (std::isinf(a)) {
if (std::isinf(x)) {
return std::numeric_limits<scalar_t>::quiet_NaN();
}
return 1.0;
}
else if (std::isinf(x)) {
return 0.0;
}
absxma_a = std::fabs(x - a) / a;
if ((a > SMALL) && (a < LARGE) && (absxma_a < SMALLRATIO)) {
return _igam_helper_asymptotic_series(a, x, 0);
}
else if ((a > LARGE) && (absxma_a < LARGERATIO / std::sqrt(a))) {
return _igam_helper_asymptotic_series(a, x, 0);
}
if (x > 1.1) {
if (x < a) {
return 1.0 - _igam_helper_series(a, x);
}
else {
return _igamc_helper_continued_fraction(a, x);
}
}
else if (x <= 0.5) {
if (-0.4 / std::log(x) < a) {
return 1.0 - _igam_helper_series(a, x);
}
else {
return _igamc_helper_series(a, x);
}
}
else {
if (x * 1.1 < a) {
return 1.0 - _igam_helper_series(a, x);
}
else {
return _igamc_helper_series(a, x);
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free