@@ -733,6 +733,64 @@ def __hash__(self):
733
733
gammaincc = GammaIncC (upgrade_to_float , name = "gammaincc" )
734
734
735
735
736
+ class GammaIncInv (BinaryScalarOp ):
737
+ """
738
+ Inverse to the regularized lower incomplete gamma function.
739
+ """
740
+
741
+ nfunc_spec = ("scipy.special.gammaincinv" , 2 , 1 )
742
+
743
+ @staticmethod
744
+ def st_impl (k , x ):
745
+ return scipy .special .gammaincinv (k , x )
746
+
747
+ def impl (self , k , x ):
748
+ return GammaIncInv .st_impl (k , x )
749
+
750
+ def grad (self , inputs , grads ):
751
+ (k , x ) = inputs
752
+ (gz ,) = grads
753
+ return [
754
+ grad_not_implemented (self , 0 , k ),
755
+ gz * exp (gammaincinv (k , x )) * gamma (k ) * (gammaincinv (k , x ) ** (1 - k )),
756
+ ]
757
+
758
+ def c_code (self , * args , ** kwargs ):
759
+ raise NotImplementedError ()
760
+
761
+
762
+ gammaincinv = GammaIncInv (upgrade_to_float , name = "gammaincinv" )
763
+
764
+
765
+ class GammaIncCInv (BinaryScalarOp ):
766
+ """
767
+ Inverse to the regularized upper incomplete gamma function.
768
+ """
769
+
770
+ nfunc_spec = ("scipy.special.gammainccinv" , 2 , 1 )
771
+
772
+ @staticmethod
773
+ def st_impl (k , x ):
774
+ return scipy .special .gammainccinv (k , x )
775
+
776
+ def impl (self , k , x ):
777
+ return GammaIncCInv .st_impl (k , x )
778
+
779
+ def grad (self , inputs , grads ):
780
+ (k , x ) = inputs
781
+ (gz ,) = grads
782
+ return [
783
+ grad_not_implemented (self , 0 , k ),
784
+ gz * - exp (gammainccinv (k , x )) * gamma (k ) * (gammainccinv (k , x ) ** (1 - k )),
785
+ ]
786
+
787
+ def c_code (self , * args , ** kwargs ):
788
+ raise NotImplementedError ()
789
+
790
+
791
+ gammainccinv = GammaIncCInv (upgrade_to_float , name = "gammainccinv" )
792
+
793
+
736
794
def _make_scalar_loop (n_steps , init , constant , inner_loop_fn , name , loop_op = ScalarLoop ):
737
795
init = [as_scalar (x ) if x is not None else None for x in init ]
738
796
constant = [as_scalar (x ) for x in constant ]
@@ -1648,6 +1706,43 @@ def inner_loop(
1648
1706
return grad
1649
1707
1650
1708
1709
+ class BetaIncInv (ScalarOp ):
1710
+ """
1711
+ Inverse of the regularized incomplete beta function.
1712
+ """
1713
+
1714
+ nfunc_spec = ("scipy.special.betaincinv" , 3 , 1 )
1715
+
1716
+ def impl (self , a , b , x ):
1717
+ return scipy .special .betaincinv (a , b , x )
1718
+
1719
+ def grad (self , inputs , grads ):
1720
+ (a , b , x ) = inputs
1721
+ (gz ,) = grads
1722
+ return [
1723
+ grad_not_implemented (self , 0 , a ),
1724
+ grad_not_implemented (self , 0 , b ),
1725
+ gz
1726
+ * exp (betaln (a , b ))
1727
+ * ((1 - betaincinv (a , b , x )) ** (1 - b ))
1728
+ * (betaincinv (a , b , x ) ** (1 - a )),
1729
+ ]
1730
+
1731
+ def c_code (self , * args , ** kwargs ):
1732
+ raise NotImplementedError ()
1733
+
1734
+
1735
+ betaincinv = BetaIncInv (upgrade_to_float_no_complex , name = "betaincinv" )
1736
+
1737
+
1738
+ def betaln (a , b ):
1739
+ """
1740
+ Beta function from gamma function.
1741
+ """
1742
+
1743
+ return gammaln (a ) + gammaln (b ) - gammaln (a + b )
1744
+
1745
+
1651
1746
class Hyp2F1 (ScalarOp ):
1652
1747
"""
1653
1748
Gaussian hypergeometric function ``2F1(a, b; c; z)``.
0 commit comments