§
    Ÿ²Åjv  ã                   ó  — d dl mZ d dlmZ d dlmZmZ d dlZd dlm	c m
Z d dlmZ dZg d¢Zd„ Zd	„ Zd
„ Zdd„Zd„ Zdd„Z G d„ d¦  «        Z G d„ dee¦  «        Zddej        dedej        fd„Zddej        dedej        fd„ZdS )é    )Úupdate_wrapper)ÚNumber)ÚAnyÚDictN©Úis_tensor_likeg¶oüŒxâ?)Úbroadcast_allÚlogits_to_probsÚclamp_probsÚprobs_to_logitsÚlazy_propertyÚtril_matrix_to_vecÚvec_to_tril_matrixc                  ó”  ‡— t          d„ | D ¦   «         ¦  «        st          d¦  «        ‚t          d„ | D ¦   «         ¦  «        syt          t          j        ¦   «         ¬¦  «        Š| D ]9}t          |t          j        ¦  «        rt          |j        |j        ¬¦  «        Š nŒ:ˆfd„| D ¦   «         }t          j	        |Ž S t          j	        | Ž S )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   ó^   K  — | ](}t          |¦  «        pt          |t          ¦  «        V — Œ)d S ©N)r   Ú
isinstancer   ©Ú.0Úvs     úJC:\Projects\Historical\venv\Lib\site-packages\torch/distributions/utils.pyú	<genexpr>z broadcast_all.<locals>.<genexpr>(   s9   è è € ÐJÐJ¸a�~˜aÑ Ô Ð9¥J¨qµ&Ñ$9Ô$9ÐJÐJÐJÐJÐJÐJó    zqInput arguments must all be instances of numbers.Number, torch.Tensor or objects implementing __torch_function__.c              3   ó4   K  — | ]}t          |¦  «        V — Œd S r   r   r   s     r   r   z broadcast_all.<locals>.<genexpr>-   s*   è è € Ð1Ð1 Q�~˜aÑ Ô Ð1Ð1Ð1Ð1Ð1Ð1r   )Údtype©r   Údevicec                 óV   •— g | ]%}t          |¦  «        r|nt          j        |fi ‰¤Ž‘Œ&S © )r   ÚtorchÚtensor)r   r   Úoptionss     €r   ú
<listcomp>z!broadcast_all.<locals>.<listcomp>3   sI   ø€ ð 
ð 
ð 
ØGH• Ñ"Ô"ÐBˆAˆA­¬°QÐ(BÐ(B¸'Ð(BÐ(Bð
ð 
ð 
r   )
ÚallÚ
ValueErrorÚdictr    Úget_default_dtyper   ÚTensorr   r   Úbroadcast_tensors)ÚvaluesÚvalueÚ
new_valuesr"   s      @r   r	   r	      sÿ   ø€ õ  ÐJÐJÀ6ÐJÑJÔJÑJÔJð 
ÝðGñ
ô 
ð 	
õ Ð1Ð1¨&Ð1Ñ1Ô1Ñ1Ô1ð 	4Ý"&­UÔ-DÑ-FÔ-FÐ"GÑ"GÔ"GˆØð 	ð 	ˆEÝ˜%¥¤Ñ.Ô.ð Ý U¤[¸¼ÐFÑFÔF�Ø�ðð
ð 
ð 
ð 
ØLRð
ñ 
ô 
ˆ
õ Ô&¨
Ð3Ð3ÝÔ" FÐ+Ð+r   c                 ó  — t           j                             ¦   «         r?t          j        t          j        | ||¬¦  «        t          j        | ||¬¦  «        ¦  «        S t          j        | ||¬¦  «                             ¦   «         S )Nr   )r    Ú_CÚ_get_tracing_stateÚnormalÚzerosÚonesÚemptyÚnormal_)Úshaper   r   s      r   Ú_standard_normalr6   :   sy   € Ý„x×"Ò"Ñ$Ô$ð 
åŒ|ÝŒK˜ U°6Ð:Ñ:Ô:ÝŒJ�u E°&Ð9Ñ9Ô9ñ
ô 
ð 	
õ Œ;�u E°&Ð9Ñ9Ô9×AÒAÑCÔCÐCr   c                 óˆ   — |dk    r| S | j         d| …         dz   }|                      |¦  «                             d¦  «        S )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)éÿÿÿÿr8   )r5   ÚreshapeÚsum)r+   ÚdimÚrequired_shapes      r   Ú_sum_rightmostr=   D   sI   € ð ˆa‚x€xØˆØ”[  3 $ Ô'¨%Ñ/€NØ�=Š=˜Ñ(Ô(×,Ò,¨RÑ0Ô0Ð0r   Fc                 óZ   — |rt          j        | ¦  «        S t          j        | d¬¦  «        S )a  
    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.
    r8   )r;   )r    ÚsigmoidÚFÚsoftmax)ÚlogitsÚ	is_binarys     r   r
   r
   R   s1   € ð ð %ÝŒ}˜VÑ$Ô$Ð$ÝŒ9�V Ð$Ñ$Ô$Ð$r   c                 ór   — t          j        | j        ¦  «        j        }|                      |d|z
  ¬¦  «        S )a   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)ÚprobsrI   s     r   r   r   ^   s2   € õ, Œ+�e”kÑ
"Ô
"Ô
&€CØ�;Š;˜3 A¨¡Gˆ;Ñ,Ô,Ð,r   c                 ó    — t          | ¦  «        }|r*t          j        |¦  «        t          j        | ¦  «        z
  S t          j        |¦  «        S )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)rK   rC   Ú
ps_clampeds      r   r   r   x   sK   € õ ˜UÑ#Ô#€JØð @ÝŒy˜Ñ$Ô$¥u¤{°J°;Ñ'?Ô'?Ñ?Ð?ÝŒ9�ZÑ Ô Ð r   c                   ó    — e Zd ZdZd„ Zdd„ZdS )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                 ó4   — || _         t          | |¦  «         d S r   )Úwrappedr   ©ÚselfrR   s     r   Ú__init__zlazy_property.__init__�   s   € ØˆŒÝ�t˜WÑ%Ô%Ð%Ð%Ð%r   Nc                 óè   — |€t          | j        ¦  «        S t          j        ¦   «         5  |                      |¦  «        }d d d ¦  «         n# 1 swxY w Y   t	          || j        j        |¦  «         |S r   )Ú_lazy_property_and_propertyrR   r    Úenable_gradÚsetattrÚ__name__)rT   ÚinstanceÚobj_typer+   s       r   Ú__get__zlazy_property.__get__‘   s©   € ØÐÝ.¨t¬|Ñ<Ô<Ð<ÝÔÑ Ô ð 	+ð 	+Ø—L’L Ñ*Ô*ˆEð	+ð 	+ð 	+ñ 	+ô 	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+øøøð 	+ð 	+ð 	+ð 	+å�˜$œ,Ô/°Ñ7Ô7Ð7Øˆs   ªAÁAÁAr   )rZ   Ú
__module__Ú__qualname__Ú__doc__rU   r]   r   r   r   r   r   …   sA   € € € € € ðð ð&ð &ð &ðð ð ð ð ð r   r   c                   ó   — e Zd ZdZd„ ZdS )rW   zžWe want lazy properties to look like multiple things.

    * property when Sphinx autodoc looks
    * lazy_property when Distribution validate_args looks
    c                 ó<   — t                                | |¦  «         d S r   )ÚpropertyrU   rS   s     r   rU   z$_lazy_property_and_property.__init__¡   s   € Ý×Ò˜$ Ñ(Ô(Ð(Ð(Ð(r   N)rZ   r^   r_   r`   rU   r   r   r   rW   rW   š   s-   € € € € € ðð ð)ð )ð )ð )ð )r   rW   ÚmatÚdiagÚreturnc           	      ó:  — | j         d         }t          j                             ¦   «         s*|| k     s||k    rt	          d|› d| › d|dz
  › d�¦  «        ‚t          j        || j        ¬¦  «        }||                     dd¦  «        |dz   z   k     }| d|f         }|S )	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.
    r8   zdiag (z) provided is outside [z, rE   z].©r   .)r5   r    r.   r/   r%   Úaranger   Úview)rd   re   Únri   Ú	tril_maskÚvecs         r   r   r   ¥   s²   € ð
 	Œ	�"Œ€AÝŒ8×&Ò&Ñ(Ô(ð N¨d°a°Rªi¨i¸4À1º9¸9ÝÐL $ÐLÐLÀ¸rÐLÐLÀQÀqÁSÐLÐLÐLÑMÔMÐMÝŒ\˜! C¤JÐ/Ñ/Ô/€FØ˜Ÿš R¨Ñ+Ô+¨t°a©xÑ8Ò8€IØ
ˆc�9ˆnÔ
€CØ€Jr   rm   c                 ó   — dd|z  z    dd|z  z   dz  d| j         d         z  z   dt          |¦  «        z  |dz   z  z   dz  z   dz  }t          j        | j        ¦  «        j        }t          j                             ¦   «         s7t          |¦  «        |z
  |k    r!t          d| j         d         › d�d	z   ¦  «        ‚t          |t          j        ¦  «        r!t          |                     ¦   «         ¦  «        nt          |¦  «        }|                      | j         d
d…         t          j        ||f¦  «        z   ¦  «        }t          j        || j        ¬¦  «        }||                     dd¦  «        |dz   z   k     }| |d|f<   |S )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.
    rE   é   é   r8   é   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.Nrh   .)r5   Úabsr    rH   r   rI   r.   r/   Úroundr%   r   r(   ÚitemÚ	new_zerosÚSizeri   r   rj   )rm   re   rk   rI   rd   ri   rl   s          r   r   r   ³   sv  € ð ˆa�$‰h‰,ˆØ��D‘‰L˜QÑ  S¤Y¨r¤]Ñ!2Ñ2°Q½¸T¹¼±]ÀdÈQÁhÑ5OÑOÐTWÑ
Wñ	Xà	ñ	
€Aõ Œ+�c”iÑ
 Ô
 Ô
$€CÝŒ8×&Ò&Ñ(Ô(ð 
­e°A©h¬h¸©l¸SÒ.@Ð.@ÝØZ¨S¬Y°r¬]ÐZÐZÐZØCñDñ
ô 
ð 	
õ & a­¬Ñ6Ô6ÐD�ˆa�fŠf‰hŒh‰Œˆ½EÀ!¹H¼H€AØ
�-Š-˜œ	 # 2 #œ­¬°Q¸°FÑ);Ô);Ñ;Ñ
<Ô
<€CÝŒ\˜! C¤JÐ/Ñ/Ô/€FØ˜Ÿš R¨Ñ+Ô+¨t°a©xÑ8Ò8€IØ€CˆˆYˆÑØ€Jr   )F)r   )Ú	functoolsr   Únumbersr   Útypingr   r   r    Útorch.nn.functionalÚnnÚ
functionalr@   Útorch.overridesr   Úeuler_constantÚ__all__r	   r6   r=   r
   r   r   r   rc   rW   r(   Úintr   r   r   r   r   ú<module>r�      s¹  ðà $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *ð (€ðð ð €ð,ð ,ð ,ðDDð Dð Dð1ð 1ð 1ð	%ð 	%ð 	%ð 	%ð-ð -ð -ð4
!ð 
!ð 
!ð 
!ðð ð ð ð ñ ô ð ð*)ð )ð )ð )ð ) -°ñ )ô )ð )ðð ˜EœLð °ð ¸E¼Lð ð ð ð ðð ˜EœLð °ð ¸E¼Lð ð ð ð ð ð r   