
    uki                    $   d dl mZ d dlmZm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 d dlmZmZ d d	lmZ d d
lmZmZ d dlZe	 	 d	 	 	 	 	 	 	 dd       Ze	 	 ddd	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 dd       Z	 	 d	 	 	 	 	 	 	 ddZy)    )annotations)overloadLiteral)config)lax)	lax_numpy)
reductions)ufuncs)_reduction_dimsAxis)promote_args_inexact)Array	ArrayLikeNc                     y N aaxisbkeepdimsreturn_signwheres         O/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/ops/special.py	logsumexpr   "   s    ux    )r   c                    y r   r   r   s         r   r   r   &   s	     ~Ar   c                     y r   r   r   s         r   r   r   *   s	     BEr   c           
     ~   |t        j                  || d      } |:t        d| |      \  }}t        j                  |dk7  |t        j                         }nt        d|       \  }|}t        ||      \  }}	t        j                  |j                  |	||t        j                         }
t        j                  t        j                  t        j                  |
      |
t        j                  |
d                  }
|r|
nt        j                  |
|      }t        j                   t        j"                  ||j%                  |j&                                    }|t        j(                  ||      }|j+                  |	||      }t        j,                  |      }|s.t        j.                  |j&                  t        j0                        st3        |      }t        j4                  t        j6                  |      |
j%                  |j&                              }|r||fS |t        j.                  |j&                  t        j0                        sgt9        j:                  d      5  t        j                  |dk  t        j<                  t        j>                  |j&                        |      }ddd       |S |S # 1 sw Y   |S xY w)aq  Log-sum-exp reduction.

  JAX implementation of :func:`scipy.special.logsumexp`.

  .. math::
    \operatorname{logsumexp} a = \log \sum_i b_i \exp a_i

  where the :math:`i` indices range over one or more dimensions to be reduced.

  Args:
    a: the input array
    axis: int or sequence of ints, default=None. Axis along which the sum to be
      computed. If None, the sum is computed along all the axes.
    b: scaling factors for the exponentials. Must be broadcastable to the shape of `a`.
    keepdims: If ``True``, the axes that are reduced are left in the output as
      dimensions of size 1.
    return_sign: If ``True``, the output will be a ``(result, sign)`` pair,
      where ``sign`` is the sign of the sums and ``result`` contains the
      logarithms of their absolute values. If ``False`` only ``result`` is
      returned and it will contain NaN values if the sums are negative.
    where: Elements to include in the reduction.

  Returns:
    Either an array ``result`` or a pair of arrays ``(result, sign)``, depending
    on the value of the ``return_sign`` argument.

  See also:
    :func:`jax.nn.logmeanexp`
  Nr   r   )r   r   r   initial)r   r   r   F)dtype) jnpr   r   npinfr   r	   maxrealr   stop_gradientselectr
   isfinite	full_likeexpand_dimsexpsubastyper!   mulsumsign
issubdtypecomplexfloatingabsaddlogr   
debug_nansarraynan)r   r   r   r   r   r   a_arrb_arrpos_dimsdimsamaxamax_with_dimsexp_asumexpr1   outs                   r   r   r   .   s   > 		%AA]'Q:LE5IIeqj%"&&1E!+q1FEE"5$/.(D	

XZX^X^W^	_$			3::food&;T3==QUWXCYZ	[$#4x)H.
''#''%!6!6u{{!CD
E%]GGE5!E99$9?&	&	$ekk23E3EF[FV\\!:;#;]2==B4F4FG			5	! IIIdQh		"&&		 BCHcI	**I	*s   AJ22J<)NNFFN)r   r   r   r   r   ArrayLike | Noner   boolr   zLiteral[False]r   rC   returnr   )NNF)r   r   r   r   r   rC   r   rD   r   zLiteral[True]r   rC   rE   ztuple[Array, Array])r   r   r   r   r   rC   r   rD   r   rD   r   rC   rE   zArray | tuple[Array, Array])
__future__r   typingr   r   jax._srcr   jax._src.laxr   jax._src.numpyr   r"   r	   r
   jax._src.numpy.reductionsr   r   jax._src.numpy.utilr   jax._src.typingr   r   numpyr#   r   r   r   r   <module>rO      s    # $   + % ! ; 4 ,  
EIeiyy3AyRbynsy 
y 
EI$A_cAA6CAL\Ah{A 
A 
EI[_EE37EHXEdE 
E FJ[_::37:HX:d:r   