diff --git a/libnd4j/include/templatemath.h b/libnd4j/include/templatemath.h index 908323369..2ce8cd338 100644 --- a/libnd4j/include/templatemath.h +++ b/libnd4j/include/templatemath.h @@ -733,6 +733,27 @@ namespace nd4j { T temp = val1; val1=val2; val2=temp; }; +// template +// math_def inline Z nd4j_gamma(X a) { +// +// } + template + math_def inline Z nd4j_igamma(X a, X x) { + Z aim = nd4j_pow(x, a) / (nd4j_exp(x) * std::tgamma(a)); + auto sum = Z(0.); + auto denom = Z(1.); + for (auto i = 0; Z(1./denom) > Z(1.0e-6); i++) { + denom *= (a + i); + sum += nd4j_pow(x, i) / denom; + } + return aim * sum; + } + + template + math_def inline Z nd4j_igammac(X a, X x) { + return Z(1.) - nd4j_igamma(a, x); + } + #ifdef __CUDACC__ namespace atomics { template