a
    h                     @   s   d dl Z d dlmZmZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZmZ d d	lmZ d
gZG dd
 d
e	ZdS )    N)OptionalUnion)Tensor)constraints)TransformedDistribution)AffineTransformExpTransform)Uniform)broadcast_alleuler_constant)_NumberGumbelc                       s   e Zd ZdZejejdZejZde	e
ef e	e
ef ee dd fddZd fdd	Zd	d
 Zee
dddZee
dddZee
dddZee
dddZdd Z  ZS )r   a  
    Samples from a Gumbel Distribution.

    Examples::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Gumbel(torch.tensor([1.0]), torch.tensor([2.0]))
        >>> m.sample()  # sample from Gumbel distribution with loc=1, scale=2
        tensor([ 1.0124])

    Args:
        loc (float or Tensor): Location parameter of the distribution
        scale (float or Tensor): Scale parameter of the distribution
    locscaleN)r   r   validate_argsreturnc                    s   t ||\| _| _t| jj}t|trLt|trLt|j	d|j
 |d}n*tt| j|j	t| jd|j
 |d}t jtdt| j dt jt|| j dg}t j|||d d S )N   )r   r   r   )r
   r   r   torchfinfoZdtype
isinstancer   r	   ZtinyZepsZ	full_liker   invr   Z	ones_likesuper__init__)selfr   r   r   r   Z	base_distZ
transforms	__class__ H/var/www/auris/lib/python3.9/site-packages/torch/distributions/gumbel.pyr   %   s    zGumbel.__init__c                    s8   |  t|}| j||_| j||_t j||dS )N)	_instance)Z_get_checked_instancer   r   expandr   r   )r   Zbatch_shaper   newr   r   r   r    =   s    zGumbel.expandc                 C   s6   | j r| | | j| | j }||  | j  S N)Z_validate_argsZ_validate_sampler   r   explog)r   valueyr   r   r   log_probD   s    
zGumbel.log_prob)r   c                 C   s   | j | jt  S r"   )r   r   r   r   r   r   r   meanJ   s    zGumbel.meanc                 C   s   | j S r"   )r   r(   r   r   r   modeN   s    zGumbel.modec                 C   s   t jt d | j S )N   )mathpisqrtr   r(   r   r   r   stddevR   s    zGumbel.stddevc                 C   s   | j dS )N   )r/   powr(   r   r   r   varianceV   s    zGumbel.variancec                 C   s   | j  dt  S )Nr   )r   r$   r   r(   r   r   r   entropyZ   s    zGumbel.entropy)N)N)__name__
__module____qualname____doc__r   realZpositiveZarg_constraintsZsupportr   r   floatr   boolr   r    r'   propertyr)   r*   r/   r2   r3   __classcell__r   r   r   r   r      s*    

)r,   typingr   r   r   r   Ztorch.distributionsr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   Ztorch.distributions.uniformr	   Ztorch.distributions.utilsr
   r   Ztorch.typesr   __all__r   r   r   r   r   <module>   s   