o
    Ö­jZH  ã                   @   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   úW/var/www/html/CropPilot/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r¤t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¡s‚t
j}|j|f }
| jr”t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 ©Néÿÿÿÿr   ©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


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



