Ë
    *êñi¼  ã                   ó”   — d dl mZmZ d dlZd dlmZ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 ed	e	¬
«      Z G d„ de	ee   «      Zy)é    )ÚGenericÚTypeVarN)ÚSizeÚTensor)Úconstraints)ÚDistribution)Ú_sum_rightmost)Ú_sizeÚIndependentÚD)Úboundc            	       óŽ  ‡ — e Zd ZU dZi Zeeej                  f   e	d<   e
e	d<   	 dde
dededz  ddfˆ 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j2                  «       fdefd„Z ej2                  «       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_constraintsÚ	base_distNÚbase_distributionÚreinterpreted_batch_ndimsÚvalidate_argsÚreturnc                 ó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 ©r   )ÚlenÚbatch_shapeÚ
ValueErrorÚevent_shaper   r   ÚsuperÚ__init__)	Úselfr   r   r   ÚshapeÚ	event_dimr   r   Ú	__class__s	           €úa/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/torch/distributions/independent.pyr   zIndependent.__init__3   sÈ   ø€ ð %¤sÐ+<×+HÑ+HÓ'IÒIÜðØ3Ð4°D¼Ð=N×=ZÑ=ZÓ9[Ð8\ð^óð ð (×3Ñ3Ð6G×6SÑ6SÑSˆØ2´SÐ9J×9VÑ9VÓ5WÑWˆ	ØÐ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   Útorchr   r   Úexpandr   r   r   r   Ú_validate_args)r   r   Ú	_instanceÚnewr    s       €r!   r&   zIndependent.expandG   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_rsampleT   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_supportX   s#   € à×)Ñ)¨AÒ-ØØ�~‰~×3Ñ3Ð3r"   c                 óŠ   — | j                   j                  }| j                  r t        j                  || j                  «      }|S r+   )r   Úsupportr   r   Úindependent)r   Úresults     r!   r1   zIndependent.support^   s9   € ð —‘×'Ñ'ˆØ×)Ò)Ü ×,Ñ,¨V°T×5SÑ5SÓTˆFØˆr"   c                 ó.   — | j                   j                  S r+   )r   Úmeanr-   s    r!   r5   zIndependent.meanf   ó   € à�~‰~×"Ñ"Ð"r"   c                 ó.   — | j                   j                  S r+   )r   Úmoder-   s    r!   r8   zIndependent.modej   r6   r"   c                 ó.   — | j                   j                  S r+   )r   Úvariancer-   s    r!   r:   zIndependent.variancen   s   € à�~‰~×&Ñ&Ð&r"   c                 ó8   — | j                   j                  |«      S r+   )r   Úsample©r   Úsample_shapes     r!   r<   zIndependent.sampler   s   € Ø�~‰~×$Ñ$ \Ó2Ð2r"   r>   c                 ó8   — | j                   j                  |«      S r+   )r   Úrsampler=   s     r!   r@   zIndependent.rsampleu   s   € Ø�~‰~×%Ñ% lÓ3Ð3r"   c                 ód   — | j                   j                  |«      }t        || j                  «      S r+   )r   Úlog_probr	   r   )r   ÚvaluerB   s      r!   rB   zIndependent.log_probx   s)   € Ø—>‘>×*Ñ*¨5Ó1ˆÜ˜h¨×(FÑ(FÓGÐGr"   c                 ób   — | j                   j                  «       }t        || j                  «      S r+   )r   Úentropyr	   r   )r   rE   s     r!   rE   zIndependent.entropy|   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!   rH   zIndependent.enumerate_support€   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)"rL   Ú
__module__Ú__qualname__Ú__doc__r   ÚdictÚstrr   Ú
ConstraintÚ__annotations__r   ÚintÚboolr   r&   Úpropertyr,   r/   Údependent_propertyr1   r   r5   r8   r:   r%   r   r<   r
   r@   rB   rE   rH   rM   Ú__classcell__)r    s   @r!   r   r      sW  ø… ñð: :<€O�T˜#˜{×5Ñ5Ð5Ñ6Ó;ØƒLð &*ñ	PàðPð $'ðPð ˜d‘{ð	Pð
 
õPõ(ð ð*˜Tò *ó ð*ð ð4 tò 4ó ð4ð
 ×#Ñ#ñó $ðð ð#�fò #ó ð#ð ð#�fò #ó ð#ð ð'˜&ò 'ó ð'ð #- %§*¡*£,ñ 3°6ó 3ð -7¨E¯J©J«Lñ 4 Eð 4¸Vó 4òHòGó?ö
r"   )Útypingr   r   r%   r   r   Útorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.utilsr	   Útorch.typesr
   Ú__all__r   r   © r"   r!   ú<module>ra      sE   ðç #ã ß Ý +Ý 9Ý 4Ý ð ˆ/€ñ ˆC�|Ô$€ôy
�, ¨¡
õ y
r"   