o
    X۷i	                     @  sx   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ee	 d Z
ejdd	d
e
ddZdddZddddZdS )z
The source code here is an adaptation with minimal changes from the following
SciPy Cython file:

https://github.com/scipy/scipy/blob/master/scipy/special/sph_harm.pxd
    )annotationsN)_core)poch_definition)lpmv_definitiona{  

#include <cupy/complex.cuh>

// include for CUDART_NAN, CUDART_INF
#include <cupy/math_constants.h>

#define NPY_PI        3.141592653589793238462643383279502884  /* pi */

// from scipy/special/sph_harm.pxd
__device__ complex<double> sph_harmonic(int m, int n, double theta, double phi)
{
    double x, prefactor;
    complex<double> val;
    int mp;

    x = cos(phi);
    if (abs(m) > n)
    {
        // sf_error.error("sph_harm", sf_error.ARG,
        //                "m should not be greater than n")
        return CUDART_NAN;
    }
    if (n < 0)
    {
        // sf_error.error("sph_harm", sf_error.ARG, "n should not be negative")
        return CUDART_NAN;
    }
    if (m < 0)
    {
        mp = -m;
        prefactor = poch(n + mp + 1, -2 * mp);
        if ((mp % 2) == 1)
        {
            prefactor = -prefactor;
        }
    }
    else
    {
        mp = m;
    }
    val = pmv_wrap(mp, n, x);
    if (m < 0)
    {
        val *= prefactor;
    }
    val *= sqrt((2*n + 1) / 4.0 / NPY_PI);
    val *= sqrt(poch(n + m + 1, -2 * m));

    complex<double> exponent(0, m * theta);
    val *= exp(exponent);

    return val;
}
cupyx_scipy_lpmv)ziiff->Fziidd->Dzllff->Fzlldd->Dz3out0 = out0_type(sph_harmonic(in0, in1, in2, in3));JSpherical Harmonic.

    .. seealso:: :meth:`scipy.special.sph_harm`

    )preambledocc                 C  s    t td t| ||||dS )r   ze`cupyx.scipy.special.sph_harm` is deprecated in CuPy v14 and are planned to be removed in the future.)out)warningswarnDeprecationWarning	_sph_harm)mnthetaphir
    r   S/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupyx/scipy/special/_sph_harm.pysph_harm[   s   r   )diff_nc                C  s   |dkrt dt|| ||S )zISpherical Harmonic.

    .. seealso:: :meth:`scipy.special.sph_harm`
    r   zDerivatives not implemented.)NotImplementedErrorr   )r   r   r   r   r   r   r   r   
sph_harm_yi   s   r   )N)__doc__
__future__r   r   cupyr   cupyx.scipy.special._pochr   cupyx.scipy.special._lpmvr   sph_harmonic_definitioncreate_ufuncr   r   r   r   r   r   r   <module>   s*    =
