
    IЦi                     :   S SK Jr  S SKJr  S SKJrJr  S SKrS SKJ	s  J
r  S SKJr  Sr/ SQrS rS	 rS
 rSS jrS rSS jr " S S5      r " S S\\5      rSS\R2                  S\S\R2                  4S jjrSS\R2                  S\S\R2                  4S jjrg)    )update_wrapper)Number)AnyDictNis_tensor_likegox?)broadcast_alllogits_to_probsclamp_probsprobs_to_logitslazy_propertytril_matrix_to_vecvec_to_tril_matrixc                     [        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`.
  - numbers.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 `numbers.Number`, `torch.*Tensor` or objects implementing __torch_function__)

Raises:
    ValueError: if any of the values is not a `numbers.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     X/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/distributions/utils.py	<genexpr> broadcast_all.<locals>.<genexpr>(   s$     J6a~a 9Jq&$996s   /1zqInput arguments must all be instances of numbers.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   -   s     1&Q~a  &s   )dtyper   device)all
ValueErrordicttorchget_default_dtyper   Tensorr   r   r   tensorbroadcast_tensors)valuesoptionsvaluer   
new_valuess        r   r	   r	      s      J6JJJ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=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_)shaper   r   s      r   _standard_normalr3   :   s^    xx""$$||KK6:JJu&9
 	
 ;;u&9AACC    c                 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)r6   )r2   reshapesum)r(   dimrequired_shapes      r   _sum_rightmostr;   D   sA     ax[[3$'%/N==(,,R00r4   c                 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.
r6   )r9   )r!   sigmoidFsoftmax)logits	is_binarys     r   r
   r
   R   s'     }}V$$99V$$r4   c                 |    [         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)probsrG   s     r   r   r   ^   s3    , ++ekk
"
&
&C;;3AG;,,r4   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)rI   rA   
ps_clampeds      r   r   r   x   s?     U#Jyy$u{{J;'???99Z  r4   c                   (    \ rS rSrSrS rSS 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.
c                 &    Xl         [        X5        g r   )wrappedr   selfrQ   s     r   __init__lazy_property.__init__   s    t%r4   Nc                     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_propertyrQ   r!   enable_gradsetattr__name__)rS   instanceobj_typer(   s       r   __get__lazy_property.__get__   sX    .t||<< LL*E !,,//7 ! s   A**
A8)rQ   r   )rZ   
__module____qualname____firstlineno____doc__rT   r]   __static_attributes__ r4   r   r   r      s    &r4   r   c                       \ rS rSrSrS rSrg)rW      zWe want lazy properties to look like multiple things.

* property when Sphinx autodoc looks
* lazy_property when Distribution validate_args looks
c                 .    [         R                  X5        g r   )propertyrT   rR   s     r   rT   $_lazy_property_and_property.__init__   s    $(r4   rd   N)rZ   r_   r`   ra   rb   rT   rc   rd   r4   r   rW   rW      s    )r4   rW   matdiagreturnc           	      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.
r6   zdiag (z) provided is outside [z, rC   z].r   .)r2   r!   r+   r,   r   aranger   view)rj   rk   nro   	tril_maskvecs         r   r   r      s    
 			"A88&&((dRi496$'>rd"QqSELMM\\!JJ/FR+tax88I
c9n
CJr4   rs   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.
rC         r6      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.Nrn   .)r2   absr!   rF   r   rG   r+   r,   roundr   r   r#   item	new_zerosSizero   r   rp   )rs   rk   rq   rG   rj   ro   rr   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Jr4   )F)r   )	functoolsr   numbersr   typingr   r   r!   torch.nn.functionalnn
functionalr>   torch.overridesr   euler_constant__all__r	   r3   r;   r
   r   r   r   rh   rW   r#   intr   r   rd   r4   r   <module>r      s    $      * (,DD1	%-4
! *)- )ELL  ELL ELL  ELL r4   