
    ukim                        d dl Zd dlmZ d dlm Z d dlmZ d dlm	Z	 d dl
mZmZ d dlmZmZ dded	ed
ededef
dZdded	ed
ededef
dZdded	ed
ededef
dZdded	ed
ededef
dZdded	ed
ededef
dZdded	ed
ededef
dZy)    N)lax)numpy)_const)promote_args_inexact)gammainc	gammaincc)Array	ArrayLikexdflocscalereturnc                    t        d| |||      \  } }}}t        | d      }t        | d      }t        j                  t        j                  | |      |      }t        j                  ||      }t        j                  t        j
                  t        j                  ||      t        j                  |            t        j                  ||            }t        j                  t        j                  t        j                  |      t        j                  t        j
                  t        j                  |      |      |                  }	t        j                  t        j                  |	t        j                  |            |      }
t        j                  t        j                  | |      t        j                   |
      S )a  Chi-square log probability distribution function.

  JAX implementation of :obj:`scipy.stats.chi2` ``logpdf``.

  The chi-square probability distribution function is given by:

  .. math::

     f(x, k) = \begin{cases}
       \frac{x^{k/2-1}e^{-x/2}}{2^{k/2}\Gamma(k/2)} & x \ge 0 \\
       0 & \mathrm{otherwise}
     \end{cases}

  for :math:`k` degrees of freedom, and where :math:`\Gamma` is the
  :func:`~jax.scipy.special.gamma` function. JAX follows the scipy
  convention of using ``df`` to denote degrees of freedom.

  Args:
    x: arraylike, value at which to evaluate the PDF
    df: arraylike, distribution shape parameter
    loc: arraylike, distribution offset parameter
    scale: arraylike, distribution scale parameter

  Returns:
    array of logpdf values.

  See Also:
    - :func:`jax.scipy.stats.chi2.cdf`
    - :func:`jax.scipy.stats.chi2.pdf`
    - :func:`jax.scipy.stats.chi2.sf`
    - :func:`jax.scipy.stats.chi2.logcdf`
    - :func:`jax.scipy.stats.chi2.logsf`
  zchi2.logpdf      )r   
_lax_constr   divsubmullognegaddlgammajnpwhereltnpinf)r   r   r   r   onetwoy	df_on_twokernel	nrml_cnst	log_probss              T/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/scipy/stats/chi2.pylogpdfr(      s"   D +=!ReL!Re1a#1a#	ggcggaou%!ggb#)773773779c2CGGAJ?3P&ggcggcjj3CGGCGGCGGCLRT<UVY4Z[\)ggcggi8&A)	366!S>BFF7I	66    c                 D    t        j                  t        | |||            S )a  Chi-square probability distribution function.

  JAX implementation of :obj:`scipy.stats.chi2` ``pdf``.

  The chi-square probability distribution function is given by:

  .. math::

     f(x, k) = \begin{cases}
       \frac{x^{k/2-1}e^{-x/2}}{2^{k/2}\Gamma(k/2)} & x \ge 0 \\
       0 & \mathrm{otherwise}
     \end{cases}

  for :math:`k` degrees of freedom, and where :math:`\Gamma` is the
  :func:`~jax.scipy.special.gamma` function. JAX follows the scipy
  convention of using ``df`` to denote degrees of freedom.

  Args:
    x: arraylike, value at which to evaluate the PDF
    df: arraylike, distribution shape parameter
    loc: arraylike, distribution offset parameter
    scale: arraylike, distribution scale parameter

  Returns:
    array of pdf values.

  See Also:
    - :func:`jax.scipy.stats.chi2.cdf`
    - :func:`jax.scipy.stats.chi2.sf`
    - :func:`jax.scipy.stats.chi2.logcdf`
    - :func:`jax.scipy.stats.chi2.logpdf`
    - :func:`jax.scipy.stats.chi2.logsf`
  )r   expr(   r   r   r   r   s       r'   pdfr-   I   s    D 
2sE*	++r)   c                 h   t        d| |||      \  } }}}t        |d      }t        t        j                  ||      t        j
                  t        | d      t        j                  t        j                  | |      t        j                  ||            t        | t        j                                    S )aQ  Chi-square cumulative distribution function.

  JAX implementation of :obj:`scipy.stats.chi2` ``cdf``.

  The cdf is defined as

  .. math::

     f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y

  where :math:`f_{pdf}` is the probability density function,
  :func:`jax.scipy.stats.chi2.pdf`. JAX follows the scipy
  convention of using ``df`` to denote degrees of freedom.

  Args:
    x: arraylike, value at which to evaluate the CDF
    df: arraylike, distribution shape parameter
    loc: arraylike, distribution offset parameter
    scale: arraylike, distribution scale parameter

  Returns:
    array of cdf values.

  See Also:
    - :func:`jax.scipy.stats.chi2.pdf`
    - :func:`jax.scipy.stats.chi2.sf`
    - :func:`jax.scipy.stats.chi2.logcdf`
    - :func:`jax.scipy.stats.chi2.logpdf`
    - :func:`jax.scipy.stats.chi2.logsf`
  zchi2.cdfr   r   )
r   r   r   r   r   clampr   r   r   r   r   r   r   r   r!   s        r'   cdfr1   n   s    > +:q"c5I!Re5!#	GGBIIA	gg3s BFF

 
r)   c                 D    t        j                  t        | |||            S )aW  Chi-square log cumulative distribution function.

  JAX implementation of :obj:`scipy.stats.chi2` ``logcdf``.

  The cdf is defined as

  .. math::

     f_{cdf}(x, k) = \int_{-\infty}^x f_{pdf}(y, k)\mathrm{d}y

  where :math:`f_{pdf}` is the probability density function,
  :func:`jax.scipy.stats.chi2.pdf`. JAX follows the scipy
  convention of using ``df`` to denote degrees of freedom.

  Args:
    x: arraylike, value at which to evaluate the CDF
    df: arraylike, distribution shape parameter
    loc: arraylike, distribution offset parameter
    scale: arraylike, distribution scale parameter

  Returns:
    array of logcdf values

  See Also:
    - :func:`jax.scipy.stats.chi2.cdf`
    - :func:`jax.scipy.stats.chi2.pdf`
    - :func:`jax.scipy.stats.chi2.sf`
    - :func:`jax.scipy.stats.chi2.logpdf`
    - :func:`jax.scipy.stats.chi2.logsf`
  )r   r   r1   r,   s       r'   logcdfr3      s    > 
QC'	((r)   c                 h   t        d| |||      \  } }}}t        |d      }t        t        j                  ||      t        j
                  t        | d      t        j                  t        j                  | |      t        j                  ||            t        | t        j                                    S )a?  Chi-square survival function.

  JAX implementation of :obj:`scipy.stats.chi2` ``sf``.

  The survival function is defined as

  .. math::

     f_{sf}(x, k) = 1 - f_{cdf}(x, k)

  where :math:`f_{cdf}(x, k)` is the cumulative distribution function,
  :func:`jax.scipy.stats.chi2.cdf`. JAX follows the scipy
  convention of using ``df`` to denote degrees of freedom.

  Args:
    x: arraylike, value at which to evaluate the SF
    df: arraylike, distribution shape parameter
    loc: arraylike, distribution offset parameter
    scale: arraylike, distribution scale parameter

  Returns:
    array of sf values.

  See Also:
    - :func:`jax.scipy.stats.chi2.cdf`
    - :func:`jax.scipy.stats.chi2.pdf`
    - :func:`jax.scipy.stats.chi2.logcdf`
    - :func:`jax.scipy.stats.chi2.logpdf`
    - :func:`jax.scipy.stats.chi2.logsf`
  zchi2.sfr   r   )
r   r   r   r   r   r/   r   r   r   r   r0   s        r'   sfr5      s    > +9aS%H!Re5!#	GGBIIA	gg3s BFF

 
r)   c                 D    t        j                  t        | |||            S )aF  Chi-square log survival function.

  JAX implementation of :obj:`scipy.stats.chi2` ``logsf``.

  The survival function is defined as

  .. math::

     f_{sf}(x, k) = 1 - f_{cdf}(x, k)

  where :math:`f_{cdf}(x, k)` is the cumulative distribution function,
  :func:`jax.scipy.stats.chi2.cdf`. JAX follows the scipy
  convention of using ``df`` to denote degrees of freedom.

  Args:
    x: arraylike, value at which to evaluate the SF
    df: arraylike, distribution shape parameter
    loc: arraylike, distribution offset parameter
    scale: arraylike, distribution scale parameter

  Returns:
    array of logsf values.

  See Also:
    - :func:`jax.scipy.stats.chi2.cdf`
    - :func:`jax.scipy.stats.chi2.pdf`
    - :func:`jax.scipy.stats.chi2.sf`
    - :func:`jax.scipy.stats.chi2.logcdf`
    - :func:`jax.scipy.stats.chi2.logpdf`
  )r   r   r5   r,   s       r'   logsfr7      s    > 
Ar3&	''r)   )r   r   )r   r   jax._srcr   r   jax._src.lax.laxr   r   jax._src.numpy.utilr   jax._src.scipy.specialr   r   jax._src.typingr	   r
   r(   r-   r1   r3   r5   r7    r)   r'   <module>r>      s     ! 1 4 6 ,-7i -7Y -7Y -79 -7UZ -7`",9 ",) ",) ",	 ",RW ",J+9 +) +) +	 +RW +\)i )Y )Y )9 )UZ )D+) + + +y +QV +\(Y (I (I () (TY (r)   