Ë
    f^(h¸  ã                   ód   — 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	 dgZ
 G d„ de«      Zy)	é    N)ÚTensor)Úconstraints)ÚDistribution)Ú_sum_rightmost)Ú_sizeÚIndependentc                   ól  ‡ — e Zd ZU dZi Zeeej                  f   e	d<   	 dˆ fd„	Z
dˆ fd„	Zedefd„«       Zedefd„«       Zej                   d„ «       Zedefd	„«       Zedefd
„«       Zedefd„«       Z ej.                  «       fdefd„Z ej.                  «       fdedefd„Zd„ Zd„ Zdd„Zd„ Zˆ xZS )r   a©  
    Reinterprets some of the batch dims of a distribution as event dims.

    This is mainly useful for changing the shape of the result of
    :meth:`log_prob`. For example to create a diagonal Normal distribution with
    the same shape as a Multivariate Normal distribution (so they are
    interchangeable), you can::

        >>> from torch.distributions.multivariate_normal import MultivariateNormal
        >>> from torch.distributions.normal import Normal
        >>> loc = torch.zeros(3)
        >>> scale = torch.ones(3)
        >>> mvn = MultivariateNormal(loc, scale_tril=torch.diag(scale))
        >>> [mvn.batch_shape, mvn.event_shape]
        [torch.Size([]), torch.Size([3])]
        >>> normal = Normal(loc, scale)
        >>> [normal.batch_shape, normal.event_shape]
        [torch.Size([3]), torch.Size([])]
        >>> diagn = Independent(normal, 1)
        >>> [diagn.batch_shape, diagn.event_shape]
        [torch.Size([]), torch.Size([3])]

    Args:
        base_distribution (torch.distributions.distribution.Distribution): a
            base distribution
        reinterpreted_batch_ndims (int): the number of batch dims to
            reinterpret as event dims
    Úarg_constraintsc                 ód  •— |t        |j                  «      kD  r$t        d|› dt        |j                  «      › �«      ‚|j                  |j                  z   }|t        |j                  «      z   }|d t        |«      |z
   }|t        |«      |z
  d  }|| _        || _        t        ‰| �  |||¬«       y )NzQExpected reinterpreted_batch_ndims <= len(base_distribution.batch_shape), actual z vs ©Úvalidate_args)ÚlenÚbatch_shapeÚ
ValueErrorÚevent_shapeÚ	base_distÚreinterpreted_batch_ndimsÚsuperÚ__init__)	ÚselfÚbase_distributionr   r   ÚshapeÚ	event_dimr   r   Ú	__class__s	           €ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributions/independent.pyr   zIndependent.__init__.   sÈ   ø€ ð %¤sÐ+<×+HÑ+HÓ'IÒIÜðØ3Ð4°D¼Ð=N×=ZÑ=ZÓ9[Ð8\ð^óð ð "×-Ñ-Ð0A×0MÑ0MÑMˆØ-´Ð4E×4QÑ4QÓ0RÑRˆ	ØÐ4œc %›j¨9Ñ4Ð5ˆØœC ›J¨Ñ2Ð4Ð5ˆØ*ˆŒØ)BˆÔ&Ü‰Ñ˜ kÀÐÕOó    c                 óV  •— | j                  t        |«      }t        j                  |«      }| j                  j                  || j                  d | j                   z   «      |_        | j                  |_        t        t        |�'  || j                  d¬«       | j                  |_
        |S )NFr   )Ú_get_checked_instancer   ÚtorchÚSizer   Úexpandr   r   r   r   Ú_validate_args)r   r   Ú	_instanceÚnewr   s       €r   r!   zIndependent.expand>   s›   ø€ Ø×(Ñ(¬°iÓ@ˆÜ—j‘j Ó-ˆØŸ™×-Ñ-Ø˜$×*Ñ*Ð+K¨T×-KÑ-KÐLÑLó
ˆŒð )-×(FÑ(FˆÔ%ÜŒk˜3Ñ(Ø˜×)Ñ)¸ð 	)ô 	
ð "×0Ñ0ˆÔØˆ
r   Úreturnc                 ó.   — | j                   j                  S ©N)r   Úhas_rsample©r   s    r   r(   zIndependent.has_rsampleK   s   € à�~‰~×)Ñ)Ð)r   c                 óN   — | j                   dkD  ry| j                  j                  S )Nr   F)r   r   Úhas_enumerate_supportr)   s    r   r+   z!Independent.has_enumerate_supportO   s#   € à×)Ñ)¨AÒ-ØØ�~‰~×3Ñ3Ð3r   c                 óŠ   — | j                   j                  }| j                  r t        j                  || j                  «      }|S r'   )r   Úsupportr   r   Úindependent)r   Úresults     r   r-   zIndependent.supportU   s7   € à—‘×'Ñ'ˆØ×)Ò)Ü ×,Ñ,¨V°T×5SÑ5SÓTˆFØˆr   c                 ó.   — | j                   j                  S r'   )r   Úmeanr)   s    r   r1   zIndependent.mean\   ó   € à�~‰~×"Ñ"Ð"r   c                 ó.   — | j                   j                  S r'   )r   Úmoder)   s    r   r4   zIndependent.mode`   r2   r   c                 ó.   — | j                   j                  S r'   )r   Úvariancer)   s    r   r6   zIndependent.varianced   s   € à�~‰~×&Ñ&Ð&r   c                 ó8   — | j                   j                  |«      S r'   )r   Úsample©r   Úsample_shapes     r   r8   zIndependent.sampleh   s   € Ø�~‰~×$Ñ$ \Ó2Ð2r   r:   c                 ó8   — | j                   j                  |«      S r'   )r   Úrsampler9   s     r   r<   zIndependent.rsamplek   s   € Ø�~‰~×%Ñ% lÓ3Ð3r   c                 ód   — | j                   j                  |«      }t        || j                  «      S r'   )r   Úlog_probr   r   )r   Úvaluer>   s      r   r>   zIndependent.log_probn   s)   € Ø—>‘>×*Ñ*¨5Ó1ˆÜ˜h¨×(FÑ(FÓGÐGr   c                 ób   — | j                   j                  «       }t        || j                  «      S r'   )r   Úentropyr   r   )r   rA   s     r   rA   zIndependent.entropyr   s'   € Ø—.‘.×(Ñ(Ó*ˆÜ˜g t×'EÑ'EÓFÐFr   c                 ón   — | j                   dkD  rt        d«      ‚| j                  j                  |¬«      S )Nr   z5Enumeration over cartesian product is not implemented)r!   )r   ÚNotImplementedErrorr   Úenumerate_support)r   r!   s     r   rD   zIndependent.enumerate_supportv   s:   € Ø×)Ñ)¨AÒ-Ü%ØGóð ð �~‰~×/Ñ/°vÐ/Ó>Ð>r   c                 ój   — | j                   j                  d| j                  › d| j                  › d�z   S )Nú(z, ú))r   Ú__name__r   r   r)   s    r   Ú__repr__zIndependent.__repr__}   s8   € à�N‰N×#Ñ#Ø�$—.‘.Ð!  D×$BÑ$BÐ#CÀ1ÐEñFð	
r   r'   )T) rH   Ú
__module__Ú__qualname__Ú__doc__r
   ÚdictÚstrr   Ú
ConstraintÚ__annotations__r   r!   ÚpropertyÚboolr(   r+   Údependent_propertyr-   r   r1   r4   r6   r   r    r8   r   r<   r>   rA   rD   rI   Ú__classcell__)r   s   @r   r   r      s&  ø… ñð: :<€O�T˜#˜{×5Ñ5Ð5Ñ6Ó;ð KOõPõ ð ð*˜Tò *ó ð*ð ð4 tò 4ó ð4ð
 ×#Ñ#ñó $ðð ð#�fò #ó ð#ð ð#�fò #ó ð#ð ð'˜&ò 'ó ð'ð #- %§*¡*£,ñ 3°6ó 3ð -7¨E¯J©J«Lñ 4 Eð 4¸Vó 4òHòGó?ö
r   )r   r   Útorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   Útorch.typesr   Ú__all__r   © r   r   ú<module>r[      s0   ðó Ý Ý +Ý 9Ý 4Ý ð ˆ/€ôs
�,õ s
r   