
    9iv                         S SK Jr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Optional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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\R6                  " 5       4S	\4S jjr\R6                  " 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	           _/var/www/html/land-doc-ocr/venv/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.expandF   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#   r0   Independent.has_rsampleS   s    ~~)))r%   c                 P    U R                   S:  a  gU R                  R                  $ )Nr   F)r   r   has_enumerate_supportr1   s    r#   r4   !Independent.has_enumerate_supportW   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#   r7   Independent.support]   s5    '')) ,,V5S5STFr%   c                 .    U R                   R                  $ r/   )r   meanr1   s    r#   r<   Independent.meand       ~~"""r%   c                 .    U R                   R                  $ r/   )r   moder1   s    r#   r@   Independent.modeh   r>   r%   c                 .    U R                   R                  $ r/   )r   variancer1   s    r#   rC   Independent.variancel   s    ~~&&&r%   c                 8    U R                   R                  U5      $ r/   )r   sampler   sample_shapes     r#   rF   Independent.samplep   s    ~~$$\22r%   rH   c                 8    U R                   R                  U5      $ r/   )r   rsamplerG   s     r#   rK   Independent.rsamples   s    ~~%%l33r%   c                 b    U R                   R                  U5      n[        X R                  5      $ r/   )r   log_probr
   r   )r   valuerN   s      r#   rN   Independent.log_probv   s'    >>**51h(F(FGGr%   c                 `    U R                   R                  5       n[        XR                  5      $ r/   )r   entropyr
   r   )r   rR   s     r#   rR   Independent.entropyz   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#   rV   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   r1   s    r#   __repr__Independent.__repr__   s8    NN##$..!D$B$B#C1EF	
r%   )r   r   r/   )T)%r[   
__module____qualname____firstlineno____doc__r   dictstrr   
Constraint__annotations__r   intr   boolr   r)   propertyr0   r4   dependent_propertyr7   r   r<   r@   rC   r(   r   rF   r   rK   rN   rR   rV   r\   __static_attributes____classcell__)r"   s   @r#   r   r      s^   : :<OT#{5556;L )-	PP $'P  ~	P
 
P P& *T * * 4t 4 4
 ## $ #f # # #f # # '& ' ' #(**, 36 3 -2JJL 4E 4V 4HG?
 
r%   )typingr   r   r   r(   r   r   torch.distributionsr    torch.distributions.distributionr	   torch.distributions.utilsr
   torch.typesr   __all__r   r    r%   r#   <module>rs      sH    - -   + 9 4  / C|$w
,
 w
r%   