
    ȅi2                        % S SK JrJr  S SKJr  S SKJrJrJrJ	r	J
r
  S SKrS SKJs  Jr  S SKJrJr  S SKJr  S SKJrJrJrJr  Sr\\   \S	'   / S
QrS\\-  S\\S4   4S jrS\\\-     S\S-  S\S-  S\4S jr S\S\S\4S jr!S*S\S\"S\4S jjr#S\S\4S jr$S*S\S\"S\4S jjr%\
" SSS9r&\
" SSS 9r' " S! S"\\&\'4   5      r( " S# S$\(\&\'4   \)5      r*S+S%\S&\S\4S' jjr+S+S(\S&\S\4S) jjr,g),    )CallableSequence)update_wrapper)AnyFinalGenericoverloadTypeVarN)SymIntTensoris_tensor_like)_dtype_NumberDeviceNumbergox?euler_constant)broadcast_alllogits_to_probsclamp_probsprobs_to_logitslazy_propertytril_matrix_to_vecvec_to_tril_matrixvaluesreturn.c                     [        S U  5       5      (       d  [        S5      e[        S U  5       5      (       d  [        [        R                  " 5       S9nU  HB  n[        U[        R                  5      (       d  M$  [        UR                  UR                  S9n  O   U  Vs/ s H,  n[        U5      (       a  UO[        R                  " U40 UD6PM.     nn[        R                  " U6 $ [        R                  " U 6 $ s  snf )a  
Given a list of values (possibly containing numbers), returns a list where each
value is broadcasted based on the following rules:
  - `torch.*Tensor` instances are broadcasted as per :ref:`_broadcasting-semantics`.
  - Number instances (scalars) are upcast to tensors having
    the same size and type as the first tensor passed to `values`.  If all the
    values are scalars, then they are upcasted to scalar Tensors.

Args:
    values (list of `Number`, `torch.*Tensor` or objects implementing __torch_function__)

Raises:
    ValueError: if any of the values is not a `Number` instance,
        a `torch.*Tensor` instance, or an instance implementing __torch_function__
c              3   f   #    U  H'  n[        U5      =(       d    [        U[        5      v   M)     g 7fN)r   
isinstancer   .0vs     S/home/james-whalen/.local/lib/python3.13/site-packages/torch/distributions/utils.py	<genexpr> broadcast_all.<locals>.<genexpr>+   s$     KFq~a :Jq'$::Fs   /1ziInput arguments must all be instances of Number, torch.Tensor or objects implementing __torch_function__.c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r!   s     r$   r%   r&   0   s     1&Q~a  &s   )dtyper(   device)all
ValueErrordicttorchget_default_dtyper    r   r(   r*   r   tensorbroadcast_tensors)r   optionsvaluer#   
new_valuess        r$   r   r      s      KFKKKG
 	
 1&111"&U-D-D-F"GE%..U[[F 
 MS
LRq""AQ(B'(BBF 	 
 &&
33""F++	
s   "3C=shaper(   r*   c           	         [         R                  R                  5       (       a=  [         R                  " [         R                  " XUS9[         R
                  " XUS95      $ [         R                  " XUS9R                  5       $ )Nr)   )r.   _C_get_tracing_statenormalzerosonesemptynormal_)r5   r(   r*   s      r$   _standard_normalr>   =   s`    
 xx""$$||KK6:JJu&9
 	
 ;;u&9AACC    r3   dimc                 x    US:X  a  U $ U R                   SU*  S-   nU R                  U5      R                  S5      $ )z
Sum out ``dim`` many rightmost dimensions of a given tensor.

Args:
    value (Tensor): A tensor of ``.dim()`` at least ``dim``.
    dim (int): The number of rightmost dims to sum out.
r   N)rB   )r5   reshapesum)r3   r@   required_shapes      r$   _sum_rightmostrF   K   sA     ax[[3$'%/N==(,,R00r?   logits	is_binaryc                 f    U(       a  [         R                  " U 5      $ [        R                  " U SS9$ )z
Converts a tensor of logits into probabilities. Note that for the
binary case, each value denotes log odds, whereas for the
multi-dimensional case, the values along the last dimension denote
the log probabilities (possibly unnormalized) of the events.
rB   )r@   )r.   sigmoidFsoftmax)rG   rH   s     r$   r   r   Y   s'     }}V$$99V$$r?   probsc                 |    [         R                  " U R                  5      R                  nU R	                  USU-
  S9$ )ah  Clamps the probabilities to be in the open interval `(0, 1)`.

The probabilities would be clamped between `eps` and `1 - eps`,
and `eps` would be the smallest representable positive number for the input data type.

Args:
    probs (Tensor): A tensor of probabilities.

Returns:
    Tensor: The clamped probabilities.

Examples:
    >>> probs = torch.tensor([0.0, 0.5, 1.0])
    >>> clamp_probs(probs)
    tensor([1.1921e-07, 5.0000e-01, 1.0000e+00])

    >>> probs = torch.tensor([0.0, 0.5, 1.0], dtype=torch.float64)
    >>> clamp_probs(probs)
    tensor([2.2204e-16, 5.0000e-01, 1.0000e+00], dtype=torch.float64)

   )minmax)r.   finfor(   epsclamp)rM   rS   s     r$   r   r   e   s3    , ++ekk
"
&
&C;;3AG;,,r?   c                     [        U 5      nU(       a.  [        R                  " U5      [        R                  " U* 5      -
  $ [        R                  " U5      $ )a  
Converts a tensor of probabilities into logits. For the binary case,
this denotes the probability of occurrence of the event indexed by `1`.
For the multi-dimensional case, the values along the last dimension
denote the probabilities of occurrence of each of the events.
)r   r.   loglog1p)rM   rH   
ps_clampeds      r$   r   r      s?     U#Jyy$u{{J;'???99Z  r?   TT)contravariantR)	covariantc                       \ rS rSrSrS\\/\4   SS4S jr\	 SSSS\
SS	4S
 jj5       r\	SS\S\
S\4S jj5       r SS\S-  S\
SS4S jjrSrg)r      z
Used as a decorator for lazy loading of class attributes. This uses a
non-data descriptor that calls the wrapped method to compute the property on
first call; thereafter replacing the wrapped method into an instance
attribute.
wrappedr   Nc                 &    Xl         [        X5        g r   )r_   r   selfr_   s     r$   __init__lazy_property.__init__   s    )0t%r?   instanceobj_typez!_lazy_property_and_property[T, R]c                     g r    rb   re   rf   s      r$   __get__lazy_property.__get__   s     /2r?   c                     g r   rh   ri   s      r$   rj   rk      s    ?Br?   z%R | _lazy_property_and_property[T, R]c                     Uc  [        U R                  5      $ [        R                  " 5          U R                  U5      nS S S 5        [	        XR                  R
                  W5        U$ ! , (       d  f       N0= fr   )_lazy_property_and_propertyr_   r.   enable_gradsetattr__name__)rb   re   rf   r3   s       r$   rj   rk      sZ     .t||<< LL*E !,,//7 ! s   A**
A8)r_   r   )rq   
__module____qualname____firstlineno____doc__r   rY   r[   rc   r	   r   rj   __static_attributes__rh   r?   r$   r   r      s    &!a 0 &T & .222(+2	,2 2 BBSBAB B 37D,/	0 r?   r   c                   6    \ rS rSrSrS\\/\4   SS4S jrSr	g)rn      zWe want lazy properties to look like multiple things.

* property when Sphinx autodoc looks
* lazy_property when Distribution validate_args looks
r_   r   Nc                 .    [         R                  X5        g r   )propertyrc   ra   s     r$   rc   $_lazy_property_and_property.__init__   s    $(r?   rh   )
rq   rr   rs   rt   ru   r   rY   r[   rc   rv   rh   r?   r$   rn   rn      s%    )!a 0 )T )r?   rn   matdiagc           	      0   U R                   S   n[        R                  R                  5       (       d$  X* :  d  X:  a  [	        SU SU*  SUS-
   S35      e[        R
                  " X R                  S9nX3R                  SS5      US-   -   :  nU SU4   nU$ )	z
Convert a `D x D` matrix or a batch of matrices into a (batched) vector
which comprises of lower triangular elements from the matrix in row order.
rB   zdiag (z) provided is outside [z, rO   z].r*   .)r5   r.   r7   r8   r,   aranger*   view)r|   r}   nr   	tril_maskvecs         r$   r   r      s    
 			"A88&&((dRi496$'>rd"QUG2NOO\\!JJ/FR+tax88I
c9n
CJr?   r   c                    SSU-  -   * SSU-  -   S-  SU R                   S   -  -   S[        U5      -  US-   -  -   S-  -   S-  n[        R                  " U R                  5      R
                  n[        R                  R                  5       (       d1  [        U5      U-
  U:  a  [        SU R                   S    S3S	-   5      e[        U[        R                  5      (       a  [        UR                  5       5      O
[        U5      nU R                  U R                   S
S [        R                  " X"45      -   5      n[        R                  " X R                   S9nXUR#                  SS5      US-   -   :  nXSU4'   U$ )z
Convert a vector or a batch of vectors into a batched `D x D`
lower triangular matrix containing elements from the vector in row order.
rO         rB      g      ?zThe size of last dimension is z which cannot be expressed as z3the lower triangular part of a square D x D matrix.Nr   .)r5   absr.   rR   r(   rS   r7   r8   roundr,   r    r   item	new_zerosSizer   r*   r   )r   r}   r   rS   r|   r   r   s          r$   r   r      sT    a$h,DLQSYYr]!22QT]dQh5OOTW
W	X		
A ++cii
 
$
$C88&&((eAhlS.@,SYYr]O;YZCD
 	
 &a66affhE!HA
--		#2QF);;
<C\\!JJ/FR+tax88IYJr?   )F)r   )-collections.abcr   r   	functoolsr   typingr   r   r   r	   r
   r.   torch.nn.functionalnn
functionalrK   r   r   torch.overridesr   torch.typesr   r   r   r   r   float__annotations____all__tupler   intr>   rF   boolr   r   r   rY   r[   r   rz   rn   r   r   rh   r?   r$   <module>r      sz   . . $ 9 9      * 7 7  6e 5,6F? ,uVS[/A ,DDC&L!DD=D TMD 	D1& 1s 1v 1	%F 	%t 	% 	%-v -& -4
!6 
!d 
!v 
! Ct$C4 GAqDM >)-1"5x )F # f F # f r?   