
    \ciK                        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          Z ee	d	d
d           Z	e	j        d             Ze	j        d             Z eeddd           Zej        d             Zej        d             Zej        d             Zej        d             Z eeddddd           Zej        d             Zej        d             Zej        d             Z eeddddd           Zej        d             Zej        d             Zej        d              Zej        d!             Zej        d"             Z eed#d$d           Zej        d%             Zej        d&             Z eed'd(d           Zej        d)             Zej        d*             Zej        d+             Zej        d,             Z ee
d-d.d/d 0          Z
e
j        d1             Ze
j        d2             Z eed3d4d/d 0          Zej        d5             Zej        d6             Zej        d7             Zej        d8             ZdS )9    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                   \    e Zd ZddddZed             Zd Zd Zd Zd	 Z	d
 Z
d Zd ZdS )
MultiUFuncNF)force_complex_outputc                   t          |t          j                  st          |t          j        j                  r|                                }n1t          |t          j        j                  r|}nt          d          t                      }|D ]_}t          |t          j                  st          d|           |
                    t          d |j        D                                  `t          |          dk    rt          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              3   L   K   | ]}|                     d           d         V   dS )z->r   N)split).0xs     j/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/scipy/special/_multiufuncs.py	<genexpr>z&MultiUFunc.__init__.<locals>.<genexpr>+   s1      .U.UAqwwt}}Q/?.U.U.U.U.U.U    r   z*All ufuncs must take the same input types.c                      dS )N r   argskwargss     r   <lambda>z%MultiUFunc.__init__.<locals>.<lambda>7   s    2 r   c                      i S Nr   r   s     r   r   z%MultiUFunc.__init__.<locals>.<lambda>8   s    R r   )
isinstancenpufunccollectionsabcMappingvaluesIterable
ValueErrorsetadd	frozensettypeslen__name___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namedocr   default_kwargsufuncs_iterseen_input_typesr#   s	            r   __init__zMultiUFunc.__init__   s~   /2844 	O/;?+BCC 6-4466O[_-EFF 6-  "5 6 6 6
  #uu$ W W!%22 E$ &D2A&D &D E E E $$Y.U.U.U.U.U%U%UVVVV#$$q(( !MNNN /
&:#-#' !	#=#= %?%?"""r   c                     | j         S r    )r1   )r9   s    r   __doc__zMultiUFunc.__doc__:   s
    zr   c                     || _         dS )z3Set `key` method by decorating a function.
        N)r6   r9   funcs     r   _override_keyzMultiUFunc._override_key>   s     			r   c                     || _         d S r    )r7   rD   s     r   _override_ufunc_default_argsz'MultiUFunc._override_ufunc_default_argsC   s    #'   r   c                     || _         d S r    )r8   rD   s     r   _override_ufunc_default_kwargsz)MultiUFunc._override_ufunc_default_kwargsF   s    %)"""r   c                 >    |j         d|_         d|_        || _        dS )z9Set `resolve_out_shapes` method by decorating a function.Nz2Resolve to output shapes based on relevant inputs.resolve_out_shapes)rB   r/   r4   rD   s     r   _override_resolve_out_shapesz'MultiUFunc._override_resolve_out_shapesI   s)    <H L,#'   r   c                     || _         d S r    )r5   rD   s     r   _override_finalize_outz!MultiUFunc._override_finalize_outQ   s    !r   c                     t          | j        t          j                  r| j        S  | j        di |}| j        |         S )z.Resolve to a ufunc based on keyword arguments.r   )r!   r0   r"   r#   r6   )r9   r   	ufunc_keys      r   _resolve_ufunczMultiUFunc._resolve_ufuncT   sI     d+RX66 	)((DI''''	$Y//r   c                 R   | j         |z  }| | j        d	i |z  } | j        d	i |}d ||j         d          D             } | j        d	i |}| j        ,t          d |D                       } | j        g |d |j                  ||j        R i |}t          d |D                       }t          |d          r3||j        dz  z   }	|	                    |	          }	|	|j         d          }
nDt          j        | }t          j        |t          j                  st          j        }|j        |fz  }
| j        rt          d |
D                       }
t          d t!          ||
          D                       }||d<    ||i |}| j        |                     |          }|S )
Nc                 6    g | ]}t          j        |          S r   )r"   asarray)r   args     r   
<listcomp>z'MultiUFunc.__call__.<locals>.<listcomp>e   s     CCC#bjooCCCr   c              3   >   K   | ]}t          j        |          V  d S r    )r"   shaper   	ufunc_args     r   r   z&MultiUFunc.__call__.<locals>.<genexpr>j   s,      $U$UYRXi%8%8$U$U$U$U$U$Ur   c              3      K   | ]<}t          |d           r|j        n t          j        t          |                    V  =dS )dtypeN)hasattrr]   r"   typerZ   s     r   r   z&MultiUFunc.__call__.<locals>.<genexpr>o   sh       %B %B)2 9@	78S8S &DY__*,(4	??*C*C%B %B %B %B %B %Br   resolve_dtypesr    c              3   @   K   | ]}t          j        d |          V  dS )y              ?N)r"   result_type)r   ufunc_out_dtypes     r   r   z&MultiUFunc.__call__.<locals>.<genexpr>   sJ       )R )R-< *,O)L)L )R )R )R )R )R )Rr   c              3   H   K   | ]\  }}t          j        ||           V  dS ))r]   N)r"   empty)r   ufunc_out_shaperc   s      r   r   z&MultiUFunc.__call__.<locals>.<genexpr>   sQ       D D<O_ HHH D D D D D Dr   outr   )r3   r7   rR   ninr8   r4   tuplenoutr^   r`   r"   rb   
issubdtypeinexactfloat64r2   zipr5   )r9   r   r   r#   
ufunc_argsufunc_kwargsufunc_arg_shapesufunc_out_shapesufunc_arg_dtypesufunc_dtypesufunc_out_dtypesrc   rg   s                r   __call__zMultiUFunc.__call__]   sz   %.((226222##--f-- DCuyjkk1BCCC
1t1;;F;;$0$$U$U*$U$U$UUU7t7  Bk	zk9J  B9I BKP: B  B  B:@ B  B  % %B %B6@%B %B %B  B  B u.// 	C/%*w2FF$33LAA#/#=  "$.2B"CorzBB 1&(jO#(:0B#B * R#( )R )R@P)R )R )R $R $R   D D/1ABBD D D D DC #&LeZ0<00*$$S))C
r   )NN)r/   
__module____qualname__r@   propertyrB   rF   rH   rJ   rM   rO   rR   rv   r   r   r   r   r      s        @&+@ @ @ @ @B   X  
( ( (* * *( ( (" " "0 0 0/ / / / /r   r   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                 n    t          | dd          } d| cxk    rdk    sn t          d|  d          | S Nr{   Fstrictr      Gdiff_n is currently only implemented for orders 0, 1, and 2, received: .r   r)   rz   s    r   _r      e     %@@@F!$ $ $ $
 
 	
 Mr   c                 .    t          j        | dd          S Nr   r"   moveaxisrg   s    r   r   r          ;sB"""r   r   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``, order ``m``, and all derivatives up
    to order ``diff_n``.

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

    See Also
    --------
    sph_legendre_p
    c                 n    t          | dd          } d| cxk    rdk    sn t          d|  d          | S r}   r   rz   s    r   r   r      r   r   c                     ddgdgz   iS Naxesr   )r   r   r   r   rz   s    r   r   r      s    RDJ<'((r   c                     t          | t          j                  r| dk     rt          d          | dz   dt	          |          z  dz   f|z   |dz   fz   fS )Nr   !n must be a non-negative integer.r   r   )r!   numbersIntegralr)   abs)nmtheta_shaperj   r{   s        r   r   r      s^    a)** >q1uu<===UAAJN#k1VaZMACCr   c                 .    t          j        | dd          S r   r   r   s    r   r   r      r   r   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)!}}
    r   F
branch_cutnormr{   c                 r    t          |dd          }d|cxk    rdk    sn t          d| d          ||fS r}   r   r   s      r   r   r   #  sj     %@@@F!$ $ $ $
 
 	
 <r   c                     | fS r    r   r   s      r   r   r   .  
    ;r   c                 .    t          j        | dd          S r   r   r   s    r   r   r   3  r   r   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``, order ``m``, and all derivatives up
    to order ``diff_n``.

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

    See Also
    --------
    assoc_legendre_p
    c                     t          |t          j                  r|dk    st          d| d          d|cxk    rdk    sn t          d| d          ||fS Nr   z1diff_n must be a non-negative integer, received: r   r   r   )r!   r   r   r)   r   s      r   r   r   M  s     011 
!IIII
 
 	
 !$ $ $ $
 
 	
 <r   c                     | fS r    r   r   s      r   r   r   \  r   r   c                     dddgdgz   iS r   r   r   s      r   r   r   a  s    RH
|+,,r   c                 >   |d         }t          | t          j                  r| dk     rt          d          t          |t          j                  r|dk     rt          d          | dz   dt	          |          z  dz   ft          j        ||          z   |dz   fz   fS )Nr{   r   r   z!m must be a non-negative integer.r   r   r!   r   r   r)   r   r"   broadcast_shapes)r   r   z_shapebranch_cut_shaperj   r   r{   s          r   r   r   f  s    HFa)** >q1uu<===a)** >q1uu<===UAAJN#
G%5667:@1*G I Ir   c                 .    t          j        | dd          S r   r   r   s    r   r   r   s  r   r   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                     t          | t          j                  r| dk     rt          d|  d          d| cxk    rdk    sn t	          d|  d          | S r   )r!   r   r   r)   NotImplementedErrorrz   s    r   r   r     s    vw/00 
fqjjIIII
 
 	
 !!$ $ $ $
 
 	
 Mr   c                 .    t          j        | dd          S r   r   r   s    r   r   r     r   r   r
   a  legendre_p_all(n, z, *, diff_n=0)

    All Legendre polynomials of the first kind up to the specified degree
    ``n`` and all derivatives up to order ``diff_n``.

    Output shape is ``(diff_n + 1, n + 1, ...)``. The entry at ``(i, j)``
    corresponds to the ``i``-th derivative and degree ``j`` for all
    ``0 <= i <= diff_n`` and ``0 <= j <= n``.

    See Also
    --------
    legendre_p
    c                 n    t          | dd          } d| cxk    rdk    sn t          d|  d          | S r}   r   rz   s    r   r   r     r   r   c                     dddgiS )Nr   r   )r   r   r   rz   s    r   r   r     s    RM""r   c                 N    t          | dd          } || dz   f|z   |dz   fz   fz  S )Nr   Fr~   r   r   )r   r   rj   r{   s       r   r   r     s:    As5111AAE8g%!5777r   c                 .    t          j        | dd          S r   r   r   s    r   r   r     r   r   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   r{   c                 n    t          | dd          } d| cxk    rdk    sn t          d|  d          | S r}   r   rz   s    r   r   r   !  r   r   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    r-| 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 Nr   r   ).r   r   r   .r      rY   r   s    r   r   r   ,      	"9~	"9~s3AA#6777	"IC!Q!Q$7 8q!fq!f%AA'778: 	: 	r   r   a  sph_harm_y_all(n, m, theta, phi, *, diff_n=0)

    All spherical harmonics up to the specified degree ``n``, order ``m``,
    and all derivatives up to order ``diff_n``.

    Returns a tuple of length ``diff_n + 1`` (if ``diff_n > 0``). The first
    entry corresponds to the spherical harmonics, the second entry
    (if ``diff_n >= 1``) to the gradient, and the third entry
    (if ``diff_n >= 2``)  to the Hessian matrix. Each entry is an array of
    shape ``(n + 1, 2 * m + 1, ...)``, where the entry at ``(i, j)``
    corresponds to degree ``i`` and order ``j`` for all ``0 <= i <= n``
    and ``-m <= j <= m``.

    See Also
    --------
    sph_harm_y
    c                 n    t          | dd          } d| cxk    rdk    sn t          d|  d          | S )Nr{   Fr~   r   r   z=diff_n is currently only implemented for orders 2, received: r   r   rz   s    r   r   r   P  r   r   c                     dddgdgz   iS )Nr   r   )r   r   r   r   rz   s    r   r   r   [  s    RH//00r   c                     |d         }t          | t          j                  r| dk     rt          d          | dz   dt	          |          z  dz   ft          j        ||          z   |dz   |dz   fz   fS )Nr{   r   r   r   r   r   )r   r   r   	phi_shaperj   r   r{   s          r   r   r   `  s    HFa)** >q1uu<===UAAJN#b&9+y&Q&QQ	!VaZ ! # #r   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    r-| 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 r   r   r   s    r   r   r   k  r   r   )r$   r   numpyr"   _input_validationr   _special_ufuncsr   r   r   r	   _gufuncsr
   r   r   r   __all__r   rF   r   rO   rJ   rM   rH   r   r   r   <module>r      s            2 2 2 2 2 2: : : : : : : : : : : :; ; ; ; ; ; ; ; ; ; ; ;	 	 	t t t t t t t tn  @ G$ $ $N    &# # '&#  Z #   * !  "! 2) ) 32) 0D D 10D *# # +*# :$H E!O( ( ( V     .  /. (# # )(# "z E!#   * #  $# 2  32 4- - 54- 2	I 	I 32	I ,# # -,# Z8 ?     
F 
 
 
 "# # #"#    &    .# # /.# ,8 8 -,8 &# # '&# Z=z #1AA A A
H    "	: 	: #"	:   #1'  .    .1 1 /.1 ,# # -,# &	: 	: '&	: 	: 	:r   