
    uki                         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ed	efd
Zdeded	efdZdeded	efdZdeded	efdZy)    N)lax)numpy)_const)promote_dtypes_inexact)gammalnxlogy)Array	ArrayLikexreturnc                     t        j                  | d      }t        j                  | dkD  d      t        |dz
        dk  z  S )Nr   axis   gư>)jnpsumallabs)r   x_sums     Y/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/scipy/stats/dirichlet.py_is_simplexr      s9    
''!!
%	QQ	3uqy>D#8	99    alphac                 &    t        t        | |       S )aV  Dirichlet log probability distribution function.

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

  The Dirichlet probability density function is

  .. math::

     f(\mathbf{x}) = \frac{1}{B(\mathbf{\alpha})} \prod_{i=1}^K x_i^{\alpha_i - 1}

  where :math:`B(\mathbf{\alpha})` is the :func:`~jax.scipy.special.beta` function
  in a :math:`K`-dimensional vector space.

  Args:
    x: arraylike, value at which to evaluate the PDF
    alpha: arraylike, distribution shape parameter

  Returns:
    array of logpdf values.

  See Also:
    :func:`jax.scipy.stats.dirichlet.pdf`
  )_logpdfr   r   r   s     r   logpdfr      s    0 
(E2	33r   c           
         |j                   dk7  rt        d|j                         | j                  d   |j                  d   |j                  d   dz
  fvr%t        d| j                   d|j                         t        | d      }| j                  d   |j                  d   k7  r>t	        j
                  | t        j                  || j                  dd            gd      } t	        j                  t        |            t        t	        j                  |            z
  }| j                   dkD  r4t        j                  ||j                  d	| j                   dz
  z  z   d
      }t        j                  t	        j                  t        t        j                  ||      |       d      |      }t	        j                  t        |       |t        j                         S )Nr   z1`alpha` must be one-dimensional; got alpha.shape=r   z[`x` must have either the same number of entries as `alpha` or one entry fewer; got x.shape=z, alpha.shape=T)keepdimsr   )r   )r   )ndim
ValueErrorshape
_lax_constr   concatenater   subr   r   broadcast_in_dimr   wherer   npinf)r   r   onenormalize_term	log_probss        r   r   r   8   su   
ZZ1_
9%++G  WWQZAA(:;;
))*	}N  	1a#WWQZ5;;q>!CGGCq4)@ABKA7775>*WSWWU^-DD.VVaZ  daffqj6I(I4PEggcggeCGGE3$7;!DnU)	;q>9rvvg	66r   c                 @    t        j                  t        | |            S )aO  Dirichlet probability distribution function.

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

  The Dirichlet probability density function is

  .. math::

     f(\mathbf{x}) = \frac{1}{B(\mathbf{\alpha})} \prod_{i=1}^K x_i^{\alpha_i - 1}

  where :math:`B(\mathbf{\alpha})` is the :func:`~jax.scipy.special.beta` function
  in a :math:`K`-dimensional vector space.

  Args:
    x: arraylike, value at which to evaluate the PDF
    alpha: arraylike, distribution shape parameter

  Returns:
    array of pdf values.

  See Also:
    :func:`jax.scipy.stats.dirichlet.logpdf`
  )r   expr   r   s     r   pdfr/   L   s    0 
5!	""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   r   r/    r   r   <module>r6      s}      ! 1 6 1 ,:5 :U :
4i 4	 4e 447u 7U 7u 7(#9 #Y #5 #r   