a
    MSic                     @   sX   d dl 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
 G dd deZdS )	    )NumberN)nan)constraints)Distribution)broadcast_allc                       s   e Zd ZdZejdddejddddZdZedd Z	ed	d
 Z
edd Zedd Zd  fdd	Zd! fdd	Zejddddd Ze fddZdd Zdd Zdd Zdd Z  ZS )"Uniforma  
    Generates uniformly distributed random samples from the half-open interval
    ``[low, high)``.

    Example::

        >>> m = Uniform(torch.tensor([0.0]), torch.tensor([5.0]))
        >>> m.sample()  # uniformly distributed in the range [0.0, 5.0)
        tensor([ 2.3418])

    Args:
        low (float or Tensor): lower range (inclusive).
        high (float or Tensor): upper range (exclusive).
    Fr   )is_discrete	event_dim)lowhighTc                 C   s   | j | j d S )N   r   r
   self r   W/var/www/html/django/DPS/env/lib/python3.9/site-packages/torch/distributions/uniform.pymean   s    zUniform.meanc                 C   s
   t | j S N)r   r   r   r   r   r   mode"   s    zUniform.modec                 C   s   | j | j d S )NgLXz@r   r   r   r   r   stddev&   s    zUniform.stddevc                 C   s   | j | j dd S )Nr      )r   r
   powr   r   r   r   variance*   s    zUniform.varianceNc                    st   t ||\| _| _t|tr0t|tr0t }n
| j }tt	| j
||d | jrpt| j| j sptdd S )Nvalidate_argsz&Uniform is not defined when low>= high)r   r
   r   
isinstancer   torchSizesizesuperr   __init___validate_argsltall
ValueError)r   r
   r   r   batch_shape	__class__r   r   r    .   s    

zUniform.__init__c                    sR   |  t|}t|}| j||_| j||_tt|j|dd | j	|_	|S )NFr   )
_get_checked_instancer   r   r   r
   expandr   r   r    r!   )r   r%   	_instancenewr&   r   r   r)   :   s    
zUniform.expandc                 C   s   t | j| jS r   )r   intervalr
   r   r   r   r   r   supportC   s    zUniform.supportc                 C   s8   |  |}tj|| jj| jjd}| j|| j| j   S )N)dtypedevice)_extended_shaper   randr
   r.   r/   r   )r   sample_shapeshaper1   r   r   r   rsampleG   s    
zUniform.rsamplec                 C   sZ   | j r| | | j|| j}| j|| j}t|	|t| j| j  S r   )
r!   _validate_sampler
   letype_asr   gtr   logmul)r   valuelbZubr   r   r   log_probL   s
    
zUniform.log_probc                 C   s4   | j r| | || j | j| j  }|jdddS )Nr      )minmax)r!   r5   r
   r   clampr   r;   resultr   r   r   cdfS   s    
zUniform.cdfc                 C   s   || j | j  | j }|S r   r   rB   r   r   r   icdfY   s    zUniform.icdfc                 C   s   t | j| j S r   )r   r9   r   r
   r   r   r   r   entropy]   s    zUniform.entropy)N)N)__name__
__module____qualname____doc__r   	dependentarg_constraintshas_rsamplepropertyr   r   r   r   r    r)   dependent_propertyr-   r   r   r4   r=   rD   rE   rF   __classcell__r   r   r&   r   r   
   s,   



	
r   )numbersr   r   Z
torch._sixr   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   r   r   r   r   r   <module>   s   