
    '}hp                     p    d dl Z d dlmZ 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gZ G d de	      Zy)	    N)Number)infnan)constraints)Distribution)broadcast_allCauchyc                        e Zd ZdZej
                  ej                  dZej
                  ZdZ	d fd	Z
d fd	Zed        Zed        Zed        Z ej"                         fd	Zd
 Zd Zd Zd Z xZS )r	   aC  
    Samples from a Cauchy (Lorentz) distribution. The distribution of the ratio of
    independent normally distributed random variables with means `0` follows a
    Cauchy distribution.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Cauchy(torch.tensor([0.0]), torch.tensor([1.0]))
        >>> m.sample()  # sample from a Cauchy distribution with loc=0 and scale=1
        tensor([ 2.3214])

    Args:
        loc (float or Tensor): mode or median of the distribution.
        scale (float or Tensor): half width at half maximum.
    )locscaleTc                     t        ||      \  | _        | _        t        |t              r%t        |t              rt        j                         }n| j                  j                         }t        | %  ||       y )Nvalidate_args)
r   r   r   
isinstancer   torchSizesizesuper__init__)selfr   r   r   batch_shape	__class__s        Y/var/www/html/test/engine/venv/lib/python3.12/site-packages/torch/distributions/cauchy.pyr   zCauchy.__init__"   sW    ,S%8$*c6"z%'@**,K((--/KMB    c                 *   | j                  t        |      }t        j                  |      }| j                  j                  |      |_        | j                  j                  |      |_        t        t        |#  |d       | j                  |_	        |S )NFr   )
_get_checked_instancer	   r   r   r   expandr   r   r   _validate_args)r   r   	_instancenewr   s       r   r   zCauchy.expand*   st    ((;jj-((//+.JJ%%k2	fc#Ku#E!00
r   c                     t        j                  | j                         t        | j                  j
                  | j                  j                        S N)dtypedevice)r   full_extended_shaper   r   r#   r$   r   s    r   meanzCauchy.mean3   5    zz  "Ctxx~~dhhoo
 	
r   c                     | j                   S N)r   r'   s    r   modezCauchy.mode9   s    xxr   c                     t        j                  | j                         t        | j                  j
                  | j                  j                        S r"   )r   r%   r&   r   r   r#   r$   r'   s    r   variancezCauchy.variance=   r)   r   c                     | j                  |      }| j                  j                  |      j                         }| j                  || j                  z  z   S r+   )r&   r   r    cauchy_r   )r   sample_shapeshapeepss       r   rsamplezCauchy.rsampleC   sE    $$\2hhll5!))+xx#

***r   c                    | j                   r| j                  |       t        j                  t        j                         | j
                  j                         z
  || j                  z
  | j
                  z  dz  j                         z
  S )N   )r   _validate_samplemathlogpir   r   log1pr   values     r   log_probzCauchy.log_probH   sl    !!%(XXdggjjnn!TZZ/A5<<>?	
r   c                     | j                   r| j                  |       t        j                  || j                  z
  | j
                  z        t        j                  z  dz   S Ng      ?)r   r7   r   atanr   r   r8   r:   r<   s     r   cdfz
Cauchy.cdfQ   sH    !!%(zz5488+tzz9:TWWDsJJr   c                     t        j                  t        j                  |dz
  z        | j                  z  | j
                  z   S r@   )r   tanr8   r:   r   r   r<   s     r   icdfzCauchy.icdfV   s0    yyECK01DJJ>IIr   c                     t        j                  dt         j                  z        | j                  j                         z   S )N   )r8   r9   r:   r   r'   s    r   entropyzCauchy.entropyY   s)    xxDGG$tzz~~'777r   r+   )__name__
__module____qualname____doc__r   realpositivearg_constraintssupporthas_rsampler   r   propertyr(   r,   r.   r   r   r4   r>   rB   rE   rH   __classcell__)r   s   @r   r	   r	      s      *..9M9MNOGKC 
 

   
 

 $.5::< +

K
J8r   )r8   numbersr   r   r   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   __all__r	    r   r   <module>rZ      s/        + 9 3*M8\ M8r   