
    [Th                     d    S SK r S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S/r
 " S S\5      rg)	    N)Tensor)constraints)Distribution)_sum_rightmost)_sizeIndependentc                     ^  \ rS rSr% Sr0 r\\\R                  4   \
S'    SU 4S jjrSU 4S jjr\S\4S j5       r\S\4S j5       r\R"                  S	 5       r\S\4S
 j5       r\S\4S j5       r\S\4S j5       r\R0                  " 5       4S\4S jjr\R0                  " 5       4S\S\4S jjrS rS rSS jrS rSr U =r!$ )r      aI  
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                 Z  > U[        UR                  5      :  a$  [        SU S[        UR                  5       35      eUR                  UR                  -   nU[        UR                  5      -   nUS [        U5      U-
   nU[        U5      U-
  S  nXl        X l        [        TU ]  XgUS9  g )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	           W/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributions/independent.pyr   Independent.__init__.   s     %s+<+H+H'II34D=N=Z=Z9[8\^  "--0A0M0MM-4E4Q4Q0RR	4c%j945CJ245*)B&O    c                 N  > U R                  [        U5      n[        R                  " U5      nU R                  R                  XR                  S U R                   -   5      Ul        U R                  Ul        [        [        U]'  XR                  SS9  U R                  Ul
        U$ )NFr   )_get_checked_instancer   torchSizer   expandr   r   r   r   _validate_args)r   r   	_instancenewr   s       r   r#   Independent.expand>   s    ((i@jj---**+KT-K-KLL
 )-(F(F%k3()) 	) 	
 "00
r   returnc                 .    U R                   R                  $ N)r   has_rsampler   s    r   r+   Independent.has_rsampleK   s    ~~)))r   c                 P    U R                   S:  a  gU R                  R                  $ )Nr   F)r   r   has_enumerate_supportr,   s    r   r/   !Independent.has_enumerate_supportO   s#    ))A-~~333r   c                     U R                   R                  nU R                  (       a   [        R                  " XR                  5      nU$ r*   )r   supportr   r   independent)r   results     r   r2   Independent.supportU   s5    '')) ,,V5S5STFr   c                 .    U R                   R                  $ r*   )r   meanr,   s    r   r7   Independent.mean\       ~~"""r   c                 .    U R                   R                  $ r*   )r   moder,   s    r   r;   Independent.mode`   r9   r   c                 .    U R                   R                  $ r*   )r   variancer,   s    r   r>   Independent.varianced   s    ~~&&&r   c                 8    U R                   R                  U5      $ r*   )r   sampler   sample_shapes     r   rA   Independent.sampleh   s    ~~$$\22r   rC   c                 8    U R                   R                  U5      $ r*   )r   rsamplerB   s     r   rF   Independent.rsamplek   s    ~~%%l33r   c                 b    U R                   R                  U5      n[        X R                  5      $ r*   )r   log_probr   r   )r   valuerI   s      r   rI   Independent.log_probn   s'    >>**51h(F(FGGr   c                 `    U R                   R                  5       n[        XR                  5      $ r*   )r   entropyr   r   )r   rM   s     r   rM   Independent.entropyr   s%    ..((*g'E'EFFr   c                 j    U R                   S:  a  [        S5      eU R                  R                  US9$ )Nr   z5Enumeration over cartesian product is not implemented)r#   )r   NotImplementedErrorr   enumerate_support)r   r#   s     r   rQ   Independent.enumerate_supportv   s:    ))A-%G  ~~//v/>>r   c                 j    U R                   R                  SU R                   SU R                   S3-   $ )N(z, ))r   __name__r   r   r,   s    r   __repr__Independent.__repr__}   s8    NN##$..!D$B$B#C1EF	
r   )r   r   r*   )T)"rV   
__module____qualname____firstlineno____doc__r   dictstrr   
Constraint__annotations__r   r#   propertyboolr+   r/   dependent_propertyr2   r   r7   r;   r>   r!   r"   rA   r   rF   rI   rM   rQ   rW   __static_attributes____classcell__)r   s   @r   r   r      s'   : :<OT#{5556; KOP  *T * * 4t 4 4
 ## $ #f # # #f # # '& ' ' #(**, 36 3 -2JJL 4E 4V 4HG?
 
r   )r!   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   torch.typesr   __all__r    r   r   <module>rl      s0      + 9 4  /s
, s
r   