Ë
    P/æjP  ã                   ód   — d dl mZ 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gZ G d„ de«      Zy)	é    )ÚDictN)Úconstraints)ÚDistribution)Ú_sum_rightmost)Ú_sizeÚIndependentc                   ó\  ‡ — 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„ «       Zed„ «       Zej                  d„ «       Zed„ «       Zed	„ «       Zed
„ «       Z ej*                  «       fd„Z ej*                  «       fdedej0                  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	           €úb/root/repos/pocs/video-evals/.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   c                 ó.   — | j                   j                  S ©N)r   Úhas_rsample©r   s    r   r'   zIndependent.has_rsampleJ   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_supportN   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.supportT   s7   € à—‘×'Ñ'ˆØ×)Ò)Ü ×,Ñ,¨V°T×5SÑ5SÓTˆFØˆr   c                 ó.   — | j                   j                  S r&   )r   Úmeanr(   s    r   r0   zIndependent.mean[   ó   € à�~‰~×"Ñ"Ð"r   c                 ó.   — | j                   j                  S r&   )r   Úmoder(   s    r   r3   zIndependent.mode_   r1   r   c                 ó.   — | j                   j                  S r&   )r   Úvariancer(   s    r   r5   zIndependent.variancec   s   € à�~‰~×&Ñ&Ð&r   c                 ó8   — | j                   j                  |«      S r&   )r   Úsample©r   Úsample_shapes     r   r7   zIndependent.sampleg   s   € Ø�~‰~×$Ñ$ \Ó2Ð2r   r9   Úreturnc                 ó8   — | j                   j                  |«      S r&   )r   Úrsampler8   s     r   r<   zIndependent.rsamplej   s   € Ø�~‰~×%Ñ% lÓ3Ð3r   c                 ód   — | j                   j                  |«      }t        || j                  «      S r&   )r   Úlog_probr   r   )r   Úvaluer>   s      r   r>   zIndependent.log_probm   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.entropyq   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_supportu   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
   r   Ústrr   Ú
ConstraintÚ__annotations__r   r!   Úpropertyr'   r*   Údependent_propertyr,   r0   r3   r5   r   r    r7   r   ÚTensorr<   r>   rA   rD   rI   Ú__classcell__)r   s   @r   r   r      s   ø… ñð8 :<€O�T˜#˜{×5Ñ5Ð5Ñ6Ó;ð KOõPõ ð ñ*ó ð*ð ñ4ó ð4ð
 ×#Ñ#ñó $ðð ñ#ó ð#ð ñ#ó ð#ð ñ'ó ð'ð #- %§*¡*£,ó 3ð -7¨E¯J©J«Lñ 4 Eð 4¸U¿\¹\ó 4òHòGó?ö
r   )Útypingr   r   Útorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   Útorch.typesr   Ú__all__r   © r   r   ú<module>r[      s.   ðå ã Ý +Ý 9Ý 4Ý ð ˆ/€ôr
�,õ r
r   