o
    hv                     @   s   d dl mZ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
d
ZG dd de
ee ZdS )    )GenericOptionalTypeVarN)SizeTensor)constraints)Distribution)_sum_rightmost)_sizeIndependentD)boundc                	       s"  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e ddf fd	d
Zd' fdd	ZedefddZedefddZejdd ZedefddZedefddZedefddZe fdefddZe fdedefddZdd Zd d! Zd(d#d$Z d%d& Z!  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                    s   |t |jkrtd| dt |j |j|j }|t |j }|d t ||  }|t || d  }|| _|| _t j|||d d S )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   shapeZ	event_dimr   r   	__class__ e/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/torch/distributions/independent.pyr   3   s   zIndependent.__init__c                    s`   |  t|}t|}| j|| jd | j  |_| j|_tt|j	|| jdd | j
|_
|S )NFr   )Z_get_checked_instancer   torchr   r   expandr   r   r   r   Z_validate_args)r   r   Z	_instancenewr   r   r    r"   F   s   

zIndependent.expandc                 C      | j jS N)r   has_rsampler   r   r   r    r&   S      zIndependent.has_rsamplec                 C   s   | j dkrdS | jjS )Nr   F)r   r   has_enumerate_supportr'   r   r   r    r)   W   s   
z!Independent.has_enumerate_supportc                 C   s    | j j}| jrt|| j}|S r%   )r   supportr   r   Zindependent)r   resultr   r   r    r*   ]   s   zIndependent.supportc                 C   r$   r%   )r   meanr'   r   r   r    r,   d   r(   zIndependent.meanc                 C   r$   r%   )r   moder'   r   r   r    r-   h   r(   zIndependent.modec                 C   r$   r%   )r   variancer'   r   r   r    r.   l   r(   zIndependent.variancec                 C      | j |S r%   )r   sampler   sample_shaper   r   r    r0   p      zIndependent.sampler2   c                 C   r/   r%   )r   rsampler1   r   r   r    r4   s   r3   zIndependent.rsamplec                 C   s   | j |}t|| jS r%   )r   log_probr	   r   )r   valuer5   r   r   r    r5   v   s   zIndependent.log_probc                 C   s   | j  }t|| jS r%   )r   entropyr	   r   )r   r7   r   r   r    r7   z   s   
zIndependent.entropyTc                 C   s    | j dkr	td| jj|dS )Nr   z5Enumeration over cartesian product is not implemented)r"   )r   NotImplementedErrorr   enumerate_support)r   r"   r   r   r    r9   ~   s
   
zIndependent.enumerate_supportc                 C   s   | j jd| j d| j d S )N(z, ))r   __name__r   r   r'   r   r   r    __repr__   s   zIndependent.__repr__r%   )T)#r<   
__module____qualname____doc__r   dictstrr   
Constraint__annotations__r   intr   boolr   r"   propertyr&   r)   Zdependent_propertyr*   r   r,   r-   r.   r!   r   r0   r
   r4   r5   r7   r9   r=   __classcell__r   r   r   r    r      sB   
 

)typingr   r   r   r!   r   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr	   Ztorch.typesr
   __all__r   r   r   r   r   r    <module>   s   