o
    !i                     @   sR   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gZ	G dd deZ
dS )    )NumberN)constraints)Distribution)broadcast_allLaplacec                       s   e Zd ZdZejejdZej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 fddZdd Zdd Zdd Zdd Z  ZS )r   a  
    Creates a Laplace distribution parameterized by :attr:`loc` and :attr:`scale`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
        >>> m = Laplace(torch.tensor([0.0]), torch.tensor([1.0]))
        >>> m.sample()  # Laplace distributed with loc=0, scale=1
        tensor([ 0.1046])

    Args:
        loc (float or Tensor): mean of the distribution
        scale (float or Tensor): scale of the distribution
    )locscaleTc                 C      | j S Nr   self r   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torch/distributions/laplace.pymean      zLaplace.meanc                 C   r	   r
   r   r   r   r   r   mode"   r   zLaplace.modec                 C   s   d| j d S N   )r   powr   r   r   r   variance&   s   zLaplace.variancec                 C   s
   d| j  S )Ng;f?)r   r   r   r   r   stddev*   s   
zLaplace.stddevNc                    sN   t ||\| _| _t|trt|trt }n| j }t j	||d d S )Nvalidate_args)
r   r   r   
isinstancer   torchSizesizesuper__init__)r   r   r   r   batch_shape	__class__r   r   r   .   s
   

zLaplace.__init__c                    sR   |  t|}t|}| j||_| j||_tt|j|dd | j	|_	|S )NFr   )
Z_get_checked_instancer   r   r   r   expandr   r   r   _validate_args)r   r    Z	_instancenewr!   r   r   r#   6   s   
zLaplace.expandc                 C   s   |  |}t| jj}tj r8tj|| jj| jjdd d }| j| j	|
  t| j|jd   S | j||jd d}| j| j	|
  t|    S )N)dtypedevicer      )min)Z_extended_shaper   finfor   r&   Z_CZ_get_tracing_stateZrandr'   r   signlog1pabsclampZtinyr%   Zuniform_Zeps)r   Zsample_shapeshaper*   ur   r   r   rsample?   s   

 $zLaplace.rsamplec                 C   s8   | j r| | td| j  t|| j | j  S r   )r$   _validate_sampler   logr   r-   r   r   valuer   r   r   log_probM   s   
(zLaplace.log_probc                 C   sB   | j r| | dd|| j   t|| j   | j   S )N      ?)r$   r2   r   r+   r   expm1r-   r   r4   r   r   r   cdfR   s
   
zLaplace.cdfc                 C   s.   |d }| j | j|  td|    S )Nr7   )r   r   r+   r   r,   r-   )r   r5   termr   r   r   icdfY   s   &zLaplace.icdfc                 C   s   dt d| j  S )Nr(   r   )r   r3   r   r   r   r   r   entropy]   s   zLaplace.entropyr
   )__name__
__module____qualname____doc__r   realZpositiveZarg_constraintsZsupportZhas_rsamplepropertyr   r   r   r   r   r#   r   r   r1   r6   r9   r<   r=   __classcell__r   r   r!   r   r      s(    



	)numbersr   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr   __all__r   r   r   r   r   <module>   s    