o
    X۷i                     @  s   d Z ddlmZ ddlZddlmZ ddlZddlmZ ddl	m
Z
mZ zddlmZ ejZ[W n eyC   G dd	 d	Ze ZY nw d
dgZedZeejddd
ZeejdddZdddZdddZdS )z{Fast Hankel transforms using the FFTLog algorithm.
The implementation closely follows the Fortran code of Hamilton (2000).
    )annotationsN)warn)_fft)loggammapoch)fhtc                   @  s   e Zd Zdd ZdS )_DummyModulec                 C  s   d S )N )selfnamer	   r	   M/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupyx/scipy/fft/_fftlog.py__getattr__   s   z_DummyModule.__getattr__N)__name__
__module____qualname__r   r	   r	   r	   r   r      s    r   r   ifht           c           
      C  s   | j d }|dkr"|d d }t|}| t| ||  |  } t|||||d}t| |}	|dkrD|	t| || | |  9 }	|	S )a  Compute the fast Hankel transform.

    Computes the discrete Hankel transform of a logarithmically spaced periodic
    sequence using the FFTLog algorithm [1]_, [2]_.

    Parameters
    ----------
    a : cupy.ndarray (..., n)
        Real periodic input array, uniformly logarithmically spaced.  For
        multidimensional input, the transform is performed over the last axis.
    dln : float
        Uniform logarithmic spacing of the input array.
    mu : float
        Order of the Hankel transform, any positive or negative real number.
    offset : float, optional
        Offset of the uniform logarithmic spacing of the output array.
    bias : float, optional
        Exponent of power law bias, any positive or negative real number.

    Returns
    -------
    A : cupy.ndarray (..., n)
        The transformed output array, which is real, periodic, uniformly
        logarithmically spaced, and of the same shape as the input array.

    See Also
    --------
    :func:`scipy.special.fht`
    :func:`scipy.special.fhtoffset` : Return an optimal offset for `fht`.

    References
    ----------
    .. [1] Talman J. D., 1978, J. Comp. Phys., 29, 35
    .. [2] Hamilton A. J. S., 2000, MNRAS, 312, 257 (astro-ph/9905191)

    r      r   offsetbiasshapecupyarangeexpfhtcoeff_fhtq)
adlnmur   r   nj_cjuAr	   r	   r   r   "   s   
(

 c           
      C  s   | j d }|dkr#|d d }t|}| t||| | |   } t|||||d}t| |dd}	|dkrE|	t| ||  |  }	|	S )aP  Compute the inverse fast Hankel transform.

    Computes the discrete inverse Hankel transform of a logarithmically spaced
    periodic sequence. This is the inverse operation to `fht`.

    Parameters
    ----------
    A : cupy.ndarray (..., n)
        Real periodic input array, uniformly logarithmically spaced.  For
        multidimensional input, the transform is performed over the last axis.
    dln : float
        Uniform logarithmic spacing of the input array.
    mu : float
        Order of the Hankel transform, any positive or negative real number.
    offset : float, optional
        Offset of the uniform logarithmic spacing of the output array.
    bias : float, optional
        Exponent of power law bias, any positive or negative real number.

    Returns
    -------
    a : cupy.ndarray (..., n)
        The transformed output array, which is real, periodic, uniformly
        logarithmically spaced, and of the same shape as the input array.

    See Also
    --------
    :func:`scipy.special.ifht`
    :func:`scipy.special.fhtoffset` : Return an optimal offset for `fht`.

    r   r   r   r   r   T)inverser   )
r'   r!   r"   r   r   r#   r$   r%   r&   r    r	   r	   r   r   a   s   
#
c                 C  s`  ||}}|d | d }|d | d }t dtj| d  | |  | d d }	t j| d d td}
t j| d d td}|	|
jdd< ||
jdd< t|
|d ||
jdd< t|
|
d |	dt	|  9 }	|
 j|j8  _|
 jt	| 7  _|
 j|j7  _|
 j|	7  _t j
|
|
d | d dkrd|
jd< t |
d sd| t|||  |
d< |
S )z?Compute the coefficient array for a fast Hankel transform.
    r   r   r   )dtypeN)outr   )r   linspacemathpiemptycompleximagrealr   LN_2r   isfiniter   )r#   r!   r"   r   r   lnkrqxpxmyr&   vr	   r	   r   r      s,   
(
r   Fc                 C  s   | j d }t|d r|std | }d|d< n|d dkr0|r0td | }tj|d< tj| dd}|s>||9 }n||  }tj	||dd}|ddddf }|S )zUCompute the biased fast Hankel transform.

    This is the basic FFTLog routine.
    r   r   z.singular transform; consider changing the biasz6singular inverse transform; consider changing the bias)axis.N)
r   r   isinfr   copyinfr   rfftconjirfft)r    r&   r(   r#   r'   r	   r	   r   r      s    



r   )r   r   )F)__doc__
__future__r   r,   warningsr   r   cupyx.scipy.fftr   cupyx.scipy.specialr   r   	scipy.fftr   _fht
_scipy_fftImportErrorr   __all__logr2   _implementsr   r   r   r	   r	   r	   r   <module>   s.    



>
9)