o
    ?HhZH                     @   sV  d dl Z d dlZd dlZddlmZ ddlmZmZm	Z	m
Z
 ddlmZmZmZmZ g dZG dd dZee	d	d d
Z	e	jdd Ze	jdd Zeedd d
Zejdd Zejdd Zejdd Zejdd Zeedddd dZejdd Zejdd Zejdd Zeedddd dZejdd Zejdd Zejdd Zejdd Zejdd Zeed d d
Zejd!d Zejd"d Zeed#d d
Zejd$d Zejd%d Zejd&d Zejd'd Zee
d(d)d d*Z
e
jd+d Ze
jd,d Zeed-d)d d*Zejd.d Zejd/d Zejd0d Zejd1d ZdS )2    N   _nonneg_int_or_fail)
legendre_passoc_legendre_psph_legendre_p
sph_harm_y)legendre_p_allassoc_legendre_p_allsph_legendre_p_allsph_harm_y_all)r   r
   r   r	   r   r   r   r   c                   @   s`   e Zd ZdddddZedd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd ZdS )
MultiUFuncNF)force_complex_outputc                K   s   t |tjsLt |tjjr| }nt |tjjr|}ntdt	 }|D ]}t |tjs4td| |
tdd |jD  q%t|dkrLtd|| _|| _|| _|| _d | _d | _d | _dd | _d	d | _d S )
Nz7ufunc_or_ufuncs should be a ufunc or a ufunc collectionz2All ufuncs must have type `numpy.ufunc`. Received c                 s   s    | ]
}| d d V  qdS )z->r   N)split).0x r   Z/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/scipy/special/_multiufuncs.py	<genexpr>+   s    z&MultiUFunc.__init__.<locals>.<genexpr>r   z*All ufuncs must take the same input types.c                  _   s   dS )Nr   r   argskwargsr   r   r   <lambda>6       z%MultiUFunc.__init__.<locals>.<lambda>c                  _   s   i S Nr   r   r   r   r   r   7   r   )
isinstancenpufunccollectionsabcMappingvaluesIterable
ValueErrorsetadd	frozensettypeslen_ufunc_or_ufuncs_MultiUFunc__doc!_MultiUFunc__force_complex_output_default_kwargs_resolve_out_shapes_finalize_out_key_ufunc_default_args_ufunc_default_kwargs)selfufunc_or_ufuncsdocr   default_kwargsufuncs_iterseen_input_typesr   r   r   r   __init__   s0   

zMultiUFunc.__init__c                 C   s   | j S r   )r*   )r2   r   r   r   __doc__9      zMultiUFunc.__doc__c                 C   s
   || _ dS )z3Set `key` method by decorating a function.
        N)r/   r2   funcr   r   r   _override_key=   s   
zMultiUFunc._override_keyc                 C   
   || _ d S r   )r0   r;   r   r   r   _override_ufunc_default_argsB      
z'MultiUFunc._override_ufunc_default_argsc                 C   r>   r   )r1   r;   r   r   r   _override_ufunc_default_kwargsE   r@   z)MultiUFunc._override_ufunc_default_kwargsc                 C   s    |j du rd|_ d|_|| _dS )z9Set `resolve_out_shapes` method by decorating a function.Nz2Resolve to output shapes based on relevant inputs.resolve_out_shapes)r9   __name__r-   r;   r   r   r   _override_resolve_out_shapesH   s
   

z'MultiUFunc._override_resolve_out_shapesc                 C   r>   r   )r.   r;   r   r   r   _override_finalize_outP   r@   z!MultiUFunc._override_finalize_outc                 K   s.   t | jtjr
| jS | jdi |}| j| S )z.Resolve to a ufunc based on keyword arguments.Nr   )r   r)   r   r   r/   )r2   r   	ufunc_keyr   r   r   _resolve_ufuncS   s   
zMultiUFunc._resolve_ufuncc                 O   sn  | j |B }|| jdi |7 }| jdi |}dd ||j d  D }| jdi |}| jd urtdd |D }| jg |d |j  ||jR i |}tdd |D }t|drs||jd  }	|	|	}	|	|j d  }
nt
j| }t
|t
jst
j}|j|f }
| jrtdd |
D }
td	d t||
D }||d
< ||i |}| jd ur| |}|S )Nc                 S   s   g | ]}t |qS r   )r   asarray)r   argr   r   r   
<listcomp>d   s    z'MultiUFunc.__call__.<locals>.<listcomp>c                 s   s    | ]}t |V  qd S r   )r   shaper   	ufunc_argr   r   r   r   i   s    z&MultiUFunc.__call__.<locals>.<genexpr>c                 s   s.    | ]}t |d r|jntt|V  qdS )dtypeN)hasattrrN   r   typerL   r   r   r   r   n   s    
resolve_dtypesr   c                 s   s    | ]	}t d |V  qdS )y              ?N)r   result_type)r   ufunc_out_dtyper   r   r   r   ~   s    c                 s   s"    | ]\}}t j||d V  qdS ))rN   N)r   empty)r   ufunc_out_shaperS   r   r   r   r      s    outr   )r,   r0   rG   ninr1   r-   tuplenoutrO   rQ   r   rR   
issubdtypeinexactfloat64r+   zipr.   )r2   r   r   r   
ufunc_argsufunc_kwargsufunc_arg_shapesufunc_out_shapesufunc_arg_dtypesufunc_dtypesufunc_out_dtypesrS   rV   r   r   r   __call__\   sJ   






zMultiUFunc.__call__r   )rC   
__module____qualname__r8   propertyr9   r=   r?   rA   rD   rE   rG   re   r   r   r   r   r      s     
	r   a  sph_legendre_p(n, m, theta, *, diff_n=0)

    Spherical Legendre polynomial of the first kind.

    Parameters
    ----------
    n : ArrayLike[int]
        Degree of the spherical Legendre polynomial. Must have ``n >= 0``.
    m : ArrayLike[int]
        Order of the spherical Legendre polynomial.
    theta : ArrayLike[float]
        Input value.
    diff_n : Optional[int]
        A non-negative integer. Compute and return all derivatives up
        to order ``diff_n``. Default is 0.

    Returns
    -------
    p : ndarray or tuple[ndarray]
        Spherical Legendre polynomial with ``diff_n`` derivatives.

    Notes
    -----
    The spherical counterpart of an (unnormalized) associated Legendre polynomial has
    the additional factor

    .. math::

        \sqrt{\frac{(2 n + 1) (n - m)!}{4 \pi (n + m)!}}

    It is the same as the spherical harmonic :math:`Y_{n}^{m}(\theta, \phi)`
    with :math:`\phi = 0`.
    diff_nc                 C   8   t | ddd} d|   krdksn td|  d| S Nrj   Fstrictr      Gdiff_n is currently only implemented for orders 0, 1, and 2, received: .r   r#   ri   r   r   r   _      rs   c                 C      t | ddS Nr   r   moveaxisrV   r   r   r   rs         a|  sph_legendre_p_all(n, m, theta, *, diff_n=0)

    All spherical Legendre polynomials of the first kind up to the
    specified degree ``n`` and order ``m``.

    Output shape is ``(n + 1, 2 * m + 1, ...)``. The entry at ``(j, i)``
    corresponds to degree ``j`` and order ``i`` for all  ``0 <= j <= n``
    and ``-m <= i <= m``.

    See Also
    --------
    sph_legendre_p
    c                 C   rk   rl   rr   ri   r   r   r   rs      rt   c                 C   s   ddgdg iS Naxesr   )r   r   rw   r   ri   r   r   r   rs      s   c                 C   sD   t | tjr
| dk rtd| d dt| d f| |d f fS )Nr   !n must be a non-negative integer.r   ro   )r   numbersIntegralr#   abs)nmtheta_shaperY   rj   r   r   r   rs      s   (c                 C   ru   rv   rx   rz   r   r   r   rs      r{   a  assoc_legendre_p(n, m, z, *, branch_cut=2, norm=False, diff_n=0)

    Associated Legendre polynomial of the first kind.

    Parameters
    ----------
    n : ArrayLike[int]
        Degree of the associated Legendre polynomial. Must have ``n >= 0``.
    m : ArrayLike[int]
        order of the associated Legendre polynomial.
    z : ArrayLike[float | complex]
        Input value.
    branch_cut : Optional[ArrayLike[int]]
        Selects branch cut. Must be 2 (default) or 3.
        2: cut on the real axis ``|z| > 1``
        3: cut on the real axis ``-1 < z < 1``
    norm : Optional[bool]
        If ``True``, compute the normalized associated Legendre polynomial.
        Default is ``False``.
    diff_n : Optional[int]
        A non-negative integer. Compute and return all derivatives up
        to order ``diff_n``. Default is 0.

    Returns
    -------
    p : ndarray or tuple[ndarray]
        Associated Legendre polynomial with ``diff_n`` derivatives.

    Notes
    -----
    The normalized counterpart of an (unnormalized) associated Legendre
    polynomial has the additional factor

    .. math::

        \sqrt{\frac{(2 n + 1) (n - m)!}{2 (n + m)!}}
    ro   F
branch_cutnormrj   c                 C   s<   t |ddd}d|  krdksn td| d||fS rl   rr   r   r   r   r   rs     s   c                 C      | fS r   r   r   r   r   r   rs   (  r:   c                 C   ru   rv   rx   rz   r   r   r   rs   -  r{   a  assoc_legendre_p_all(n, m, z, *, branch_cut=2, norm=False, diff_n=0)

    All associated Legendre polynomials of the first kind up to the
    specified degree ``n`` and order ``m``.

    Output shape is ``(n + 1, 2 * m + 1, ...)``. The entry at ``(j, i)``
    corresponds to degree ``j`` and order ``i`` for all  ``0 <= j <= n``
    and ``-m <= i <= m``.

    See Also
    --------
    assoc_legendre_p
    c                 C   sR   t |tjr
|dkstd| dd|  krdks%n td| d||fS Nr   z1diff_n must be a non-negative integer, received: rq   ro   rp   )r   r   r   r#   r   r   r   r   rs   D  s   
c                 C   r   r   r   r   r   r   r   rs   S  r:   c                 C      dddgdg iS r|   r   r   r   r   r   rs   X     c                 K   sp   |d }t | tjr| dk rtdt |tjr|dk r td| d dt| d ft|| |d f fS )Nrj   r   r~   z!m must be a non-negative integer.r   ro   r   r   r   r#   r   r   broadcast_shapes)r   r   z_shapebranch_cut_shaperY   r   rj   r   r   r   rs   ]  s   
c                 C   ru   rv   rx   rz   r   r   r   rs   j  r{   a  legendre_p(n, z, *, diff_n=0)

    Legendre polynomial of the first kind.

    Parameters
    ----------
    n : ArrayLike[int]
        Degree of the Legendre polynomial. Must have ``n >= 0``.
    z : ArrayLike[float]
        Input value.
    diff_n : Optional[int]
        A non-negative integer. Compute and return all derivatives up
        to order ``diff_n``. Default is 0.

    Returns
    -------
    p : ndarray or tuple[ndarray]
        Legendre polynomial with ``diff_n`` derivatives.

    See Also
    --------
    legendre

    References
    ----------
    .. [1] Zhang, Shanjie and Jin, Jianming. "Computation of Special
           Functions", John Wiley and Sons, 1996.
           https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
    c                 C   sN   t | tjr
| dk rtd|  dd|   krdks%n td|  d| S r   )r   r   r   r#   NotImplementedErrorri   r   r   r   rs     s   
c                 C   ru   rv   rx   rz   r   r   r   rs     r{   a  legendre_p_all(n, z, *, diff_n=0)

    All Legendre polynomials of the first kind up to the
    specified degree ``n``.

    Output shape is ``(n + 1, ...)``. The entry at ``j``
    corresponds to degree ``j`` for all  ``0 <= j <= n``.

    See Also
    --------
    legendre_p
    c                 C   rk   rl   rr   ri   r   r   r   rs     rt   c                 C   s   dddgiS )Nr}   r   )r   rw   r   ri   r   r   r   rs     s   c                 C   s,   t | ddd} || d f| |d f f S )Nr   Frm   r   r   )r   r   rY   rj   r   r   r   rs     s   c                 C   ru   rv   rx   rz   r   r   r   rs     r{   a  sph_harm_y(n, m, theta, phi, *, diff_n=0)

    Spherical harmonics. They are defined as

    .. math::

        Y_n^m(\theta,\phi) = \sqrt{\frac{2 n + 1}{4 \pi} \frac{(n - m)!}{(n + m)!}}
            P_n^m(\cos(\theta)) e^{i m \phi}

    where :math:`P_n^m` are the (unnormalized) associated Legendre polynomials.

    Parameters
    ----------
    n : ArrayLike[int]
        Degree of the harmonic. Must have ``n >= 0``. This is
        often denoted by ``l`` (lower case L) in descriptions of
        spherical harmonics.
    m : ArrayLike[int]
        Order of the harmonic.
    theta : ArrayLike[float]
        Polar (colatitudinal) coordinate; must be in ``[0, pi]``.
    phi : ArrayLike[float]
        Azimuthal (longitudinal) coordinate; must be in ``[0, 2*pi]``.
    diff_n : Optional[int]
        A non-negative integer. Compute and return all derivatives up
        to order ``diff_n``. Default is 0.

    Returns
    -------
    y : ndarray[complex] or tuple[ndarray[complex]]
       Spherical harmonics with ``diff_n`` derivatives.

    Notes
    -----
    There are different conventions for the meanings of the input
    arguments ``theta`` and ``phi``. In SciPy ``theta`` is the
    polar angle and ``phi`` is the azimuthal angle. It is common to
    see the opposite convention, that is, ``theta`` as the azimuthal angle
    and ``phi`` as the polar angle.

    Note that SciPy's spherical harmonics include the Condon-Shortley
    phase [2]_ because it is part of `sph_legendre_p`.

    With SciPy's conventions, the first several spherical harmonics
    are

    .. math::

        Y_0^0(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{1}{\pi}} \\
        Y_1^{-1}(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{3}{2\pi}}
                                    e^{-i\phi} \sin(\theta) \\
        Y_1^0(\theta, \phi) &= \frac{1}{2} \sqrt{\frac{3}{\pi}}
                                 \cos(\theta) \\
        Y_1^1(\theta, \phi) &= -\frac{1}{2} \sqrt{\frac{3}{2\pi}}
                                 e^{i\phi} \sin(\theta).

    References
    ----------
    .. [1] Digital Library of Mathematical Functions, 14.30.
           https://dlmf.nist.gov/14.30
    .. [2] https://en.wikipedia.org/wiki/Spherical_harmonics#Condon.E2.80.93Shortley_phase
    T)r   rj   c                 C   rk   rl   rr   ri   r   r   r   rs     rt   c                 C      | j d dkr| d S | j d dkr!| d | dddgddgf fS | j d dkrI| d | dddgddgf | dddgddggddgddggf fS d S Nrw   r   ).r   r   ro   .r      rK   rz   r   r   r   rs        $aX  sph_harm_y_all(n, m, theta, phi, *, diff_n=0)

    All spherical harmonics up to the specified degree ``n`` and order ``m``.

    Output shape is ``(n + 1, 2 * m + 1, ...)``. The entry at ``(j, i)``
    corresponds to degree ``j`` and order ``i`` for all  ``0 <= j <= n``
    and ``-m <= i <= m``.

    See Also
    --------
    sph_harm_y
    c                 C   rk   )Nrj   Frm   r   ro   z=diff_n is currently only implemented for orders 2, received: rq   rr   ri   r   r   r   rs   =  rt   c                 C   r   )Nr}   r   )r   r   rw   r   ri   r   r   r   rs   H  r   c                 K   sZ   |d }t | tjr| dk rtd| d dt| d ft|| |d |d f fS )Nrj   r   r~   r   ro   r   )r   r   r   	phi_shaperY   r   rj   r   r   r   rs   M  s   "c                 C   r   r   r   rz   r   r   r   rs   X  r   )r   r   numpyr   _input_validationr   _special_ufuncsr   r   r   r   _gufuncsr	   r
   r   r   __all__r   r=   rs   rE   rA   rD   r?   r   r   r   r   <module>   s    v &







$*








"






=C







