o
    h                     @   sf   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
mZ dgZG dd deZdS )	    N)nanTensor)constraints)Distribution)broadcast_all)_Number_sizeUniformc                       s   e Zd ZdZejdddejddddZdZede	fdd	Z
ede	fd
dZede	fddZede	fddZd" fdd	Zd" fdd	Zejddddd Ze fdede	fddZdd Zdd Zdd Zd d! Z  ZS )#r	   a  
    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)
        >>> # xdoctest: +SKIP
        tensor([ 2.3418])

    Args:
        low (float or Tensor): lower range (inclusive).
        high (float or Tensor): upper range (exclusive).
    Fr   )is_discrete	event_dim)lowhighTreturnc                 C   s   | j | j d S )N   r   r   self r   o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/distributions/uniform.pymean%      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-   r   zUniform.stddevc                 C   s   | j | j dd S )Nr      )r   r   powr   r   r   r   variance1   s   zUniform.varianceNc                    st   t ||\| _| _t|trt|trt }n| j }t j	||d | j
r6t| j| j s8tdd S d S )Nvalidate_argsz&Uniform is not defined when low>= high)r   r   r   
isinstancer   torchSizesizesuper__init___validate_argsltall
ValueError)r   r   r   r   batch_shape	__class__r   r   r$   5   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-   A   s   
zUniform.expandc                 C   s   t | j| jS r   )r   intervalr   r   r   r   r   r   supportJ   r   zUniform.supportsample_shapec                 C   s8   |  |}tj|| jj| jjd}| j|| j| j   S )N)dtypedevice)_extended_shaper    randr   r3   r4   r   )r   r2   shaper6   r   r   r   rsampleN   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lbubr   r   r   log_probS   s
   
"zUniform.log_probc                 C   s4   | j r| | || j | j| j  }|jdddS )Nr      )minmax)r%   r9   r   r   clampr   r?   resultr   r   r   cdfZ   s   
zUniform.cdfc                 C   s   || j | j  | j }|S r   r   rG   r   r   r   icdf`   s   zUniform.icdfc                 C   s   t | j| j S r   )r    r=   r   r   r   r   r   r   entropyd   s   zUniform.entropyr   )__name__
__module____qualname____doc__r   	dependentarg_constraintshas_rsamplepropertyr   r   r   r   r   r$   r-   dependent_propertyr1   r    r!   r   r8   rB   rI   rJ   rK   __classcell__r   r   r*   r   r	      s.    	
)r    r   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   torch.typesr   r   __all__r	   r   r   r   r   <module>   s   