o
    Zh                     @   sb   d dl Z d dl 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)Tensor)constraints)Distribution)broadcast_all)_Number_sizeLaplacec                       s   e Zd ZdZejejdZej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 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  
    Creates a Laplace distribution parameterized by :attr:`loc` and :attr:`scale`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> 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scaleTreturnc                 C      | j S Nr	   self r   J/var/www/auris/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"   1   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&   9   s   
zLaplace.expandsample_shapec                 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   r)   shaper.   ur   r   r   rsampleB   s   

 $zLaplace.rsamplec                 C   s8   | j r| | td| j  t|| j | j  S r   )r'   _validate_sampler   logr
   r1   r	   r   valuer   r   r   log_probP   s   
(zLaplace.log_probc                 C   sB   | j r| | dd|| j   t|| j   | j   S )N      ?)r'   r6   r	   r/   r   expm1r1   r
   r8   r   r   r   cdfU   s
   
zLaplace.cdfc                 C   s.   |d }| j | j|  td|    S )Nr;   )r	   r
   r/   r   r0   r1   )r   r9   termr   r   r   icdf\   s   &zLaplace.icdfc                 C   s   dt d| j  S )Nr,   r   )r   r7   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   r   r   r5   r:   r=   r@   rA   __classcell__r   r   r$   r   r      s(    	)r   r   Ztorch.distributionsr   Z torch.distributions.distributionr   Ztorch.distributions.utilsr   Ztorch.typesr   r   __all__r   r   r   r   r   <module>   s   