
    ȅi                         S SK JrJr  S SKrS SKJr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
9r " S S\	\\   5      rg)    )GenericTypeVarN)SizeTensor)constraints)Distribution)_sum_rightmost)_sizeIndependentD)boundc            	         ^  \ rS rSr% Sr0 r\\\R                  4   \
S'   \\
S'    SS\S\S\S-  S	S4U 4S
 j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\R4                  " 5       4S	\4S jjr\R4                  " 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_constraints	base_distNbase_distributionreinterpreted_batch_ndimsvalidate_argsreturnc                 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 r   )lenbatch_shape
ValueErrorevent_shaper   r   super__init__)	selfr   r   r   shape	event_dimr   r   	__class__s	           Y/home/james-whalen/.local/lib/python3.13/site-packages/torch/distributions/independent.pyr   Independent.__init__3   s     %s+<+H+H'II34D=N=Z=Z9[8\^  (336G6S6SS2S9J9V9V5WW	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   torchr   r   expandr   r   r   r   _validate_args)r   r   	_instancenewr!   s       r"   r(   Independent.expandG   s    ((i@jj---**+KT-K-KLL
 )-(F(F%k3()) 	) 	
 "00
r$   c                 .    U R                   R                  $ N)r   has_rsampler   s    r"   r/   Independent.has_rsampleT   s    ~~)))r$   c                 P    U R                   S:  a  gU R                  R                  $ )Nr   F)r   r   has_enumerate_supportr0   s    r"   r3   !Independent.has_enumerate_supportX   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"   r6   Independent.support^   s7     '')) ,,V5S5STFr$   c                 .    U R                   R                  $ r.   )r   meanr0   s    r"   r;   Independent.meanf       ~~"""r$   c                 .    U R                   R                  $ r.   )r   moder0   s    r"   r?   Independent.modej   r=   r$   c                 .    U R                   R                  $ r.   )r   variancer0   s    r"   rB   Independent.variancen   s    ~~&&&r$   c                 8    U R                   R                  U5      $ r.   )r   sampler   sample_shapes     r"   rE   Independent.sampler   s    ~~$$\22r$   rG   c                 8    U R                   R                  U5      $ r.   )r   rsamplerF   s     r"   rJ   Independent.rsampleu   s    ~~%%l33r$   c                 b    U R                   R                  U5      n[        X R                  5      $ r.   )r   log_probr	   r   )r   valuerM   s      r"   rM   Independent.log_probx   s'    >>**51h(F(FGGr$   c                 `    U R                   R                  5       n[        XR                  5      $ r.   )r   entropyr	   r   )r   rQ   s     r"   rQ   Independent.entropy|   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"   rU   Independent.enumerate_support   s:    ))A-%G  ~~//v/>>r$   c                 j    U R                   R                  SU R                   SU R                   S3-   $ )N(z, ))r!   __name__r   r   r0   s    r"   __repr__Independent.__repr__   s8    NN##$..!D$B$B#C1EF	
r$   )r   r   r.   )T)$rZ   
__module____qualname____firstlineno____doc__r   dictstrr   
Constraint__annotations__r   intboolr   r(   propertyr/   r3   dependent_propertyr6   r   r;   r?   rB   r'   r   rE   r
   rJ   rM   rQ   rU   r[   __static_attributes____classcell__)r!   s   @r"   r   r      s^   : :<OT#{5556;L &*	PP $'P d{	P
 
P P( *T * * 4t 4 4
 ## $ #f # # #f # # '& ' ' #(**, 36 3 -2JJL 4E 4V 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>rr      sE    #   + 9 4  / C|$y
,
 y
r$   