L iZHddlZddlZddlZddlmZddlmZmZm Z m Z ddl m Z m Z mZmZgdZGddZee d d Z e j$d Ze j(d Zeed d Zej$dZej*dZej,dZej(dZeeddddZej$dZej.dZej(dZee ddddZ e j$dZe j.dZe j*dZe j,dZe j(dZeedd Zej$d Zej(d!Zee d"d Z e j$d#Ze j*d$Ze j,d%Ze j(d&Zee d'd(d)Z e j$d*Ze j(d+Zeed,d(d)Zej$d-Zej*d.Zej,d/Zej(d0Zy)1N_nonneg_int_or_fail) legendre_passoc_legendre_psph_legendre_p sph_harm_y)legendre_p_allassoc_legendre_p_allsph_legendre_p_allsph_harm_y_all)rr rr r r rr cTeZdZd dddZedZdZdZdZd Z d Z d Z d Z y) MultiUFuncNF)force_complex_outputc t|tjst|tjj r|j }n2t|tjjr|}n tdt}|D]U}t|tjstd||jtd|jDWt|dkDr td||_||_||_||_d|_d|_d|_d|_d|_y)Nz7ufunc_or_ufuncs should be a ufunc or a ufunc collectionz2All ufuncs must have type `numpy.ufunc`. Received c3DK|]}|jddyw)z->rN)split).0xs `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/special/_multiufuncs.py z&MultiUFunc.__init__..+s.UAqwwt}Q/?.Us rz*All ufuncs must take the same input types.cy)Nrargskwargss rz%MultiUFunc.__init__..6sciSNrrs rrz%MultiUFunc.__init__..7sRr) isinstancenpufunc collectionsabcMappingvaluesIterable ValueErrorsetadd frozensettypeslen_ufunc_or_ufuncs_MultiUFunc__doc!_MultiUFunc__force_complex_output_default_kwargs_resolve_out_shapes _finalize_out_key_ufunc_default_args_ufunc_default_kwargs)selfufunc_or_ufuncsdocrdefault_kwargs ufuncs_iterseen_input_typesr#s r__init__zMultiUFunc.__init__s%/2884/;??+B+BC-446 O[__-E-EF-  "566 #u $ W!%2$&22A1B&DEE $$Y.U.U%UV  W #$q( !MNN / &:#-#' ! #= %?"rc|jSr )r0)r8s r__doc__zMultiUFunc.__doc__9s zzrc||_y)z3Set `key` method by decorating a function. N)r5r8funcs r _override_keyzMultiUFunc._override_key=s  rc||_yr )r6rBs r_override_ufunc_default_argsz'MultiUFunc._override_ufunc_default_argsBs #' rc||_yr )r7rBs r_override_ufunc_default_kwargsz)MultiUFunc._override_ufunc_default_kwargsEs %)"rcF|jd|_d|_||_y)z9Set `resolve_out_shapes` method by decorating a function.Nz2Resolve to output shapes based on relevant inputs.resolve_out_shapes)r@__name__r3rBs r_override_resolve_out_shapesz'MultiUFunc._override_resolve_out_shapesHs% << H L, #' rc||_yr )r4rBs r_override_finalize_outz!MultiUFunc._override_finalize_outPs !rc t|jtjr |jS|jdi|}|j|S)z.Resolve to a ufunc based on keyword arguments.r)r!r/r"r#r5)r8r ufunc_keys r_resolve_ufunczMultiUFunc._resolve_ufuncSsH d++RXX 6(( (DII'' $$Y//rc|j|z}||jdi|z }|jdi|}||j dDcgc]}t j |}}|j di|}|j*td|D}|jg|d|j ||ji|}td|D} t|dr4| |jdzz} |j| } | |j d} nVt j| } t j| tjstj} |j| fz} |j rtd| D} tdt#|| D} | |d<||i|} |j$|j%| } | Scc}w) Nc3FK|]}tj|ywr )r"shaper ufunc_args rrz&MultiUFunc.__call__..is$UYRXXi%8$Us!c3K|]:}t|dr |jntjt|<yw)dtypeN)hasattrrXr"typerUs rrz&MultiUFunc.__call__..ns>%B)29@ 78SY__*,((4 ?*C&D%BsAAresolve_dtypesr c3HK|]}tjd|yw)y?N)r" result_type)rufunc_out_dtypes rrz&MultiUFunc.__call__..~s%)R-<*,O)L)Rs "c3PK|]\}}tj|| yw))rXN)r"empty)rufunc_out_shaper^s rrz&MultiUFunc.__call__..s,Dpropertyr@rDrFrHrLrNrQrsrrrrrsI@&+@@ (*("0/rrasph_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_ncZt|dd}d|cxkrdksntd|d|SNrxFstrictrGdiff_n is currently only implemented for orders 0, 1, and 2, received: .rr)rws r_rB % @F  !    $   Mrc0tj|ddSNrr"moveaxisrbs rrr ;;sB ""ra|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 cZt|dd}d|cxkrdksntd|d|Srzrrws rrrrrcddgdgziSNaxesr)rrrrrws rrrs RDJ<' ((rct|tjr|dkr td|dzdt |zdzf|z|dzfzfS)Nr!n must be a non-negative integer.rr})r!numbersIntegralr)abs)nm theta_shaperfrxs rrrsR a)) *q1u<== UAAJN #k 1VaZM A CCrc0tj|ddSrrrs rrrrraassoc_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_cutnormrxc^t|dd}d|cxkrdksntd|d||fSrzrrs rrrsG % @F  !    $   <rc|fSr rrs rrr( ;rc0tj|ddSrrrs rrr-rraassoc_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 ct|tjr|dk\std|dd|cxkrdksntd|d||fSNrz1diff_n must be a non-negative integer, received: rr}r~)r!rrr)rs rrrDsk  0 0 1! ?xq I    !    $   <rc|fSr rrs rrrSrrcdddgdgziSrrrs rrrXs RH |+ ,,rc |d}t|tjr|dkr tdt|tjr|dkr td|dzdt |zdzft j ||z|dzfzfS)Nrxrrz!m must be a non-negative integer.rr}r!rrr)rr"broadcast_shapes)rrz_shapebranch_cut_shaperfrrxs rrr]s H F a)) *q1u<== a)) *q1u<== UAAJN # G%56 7:@1* G IIrc0tj|ddSrrrs rrrjrralegendre_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 ct|tjr|dkrtd|dd|cxkrdksnt d|d|Sr)r!rrr)NotImplementedErrorrws rrrse vw// 0fqj?xq I    ! !   $   Mrc0tj|ddSrrrs rrrrralegendre_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 cZt|dd}d|cxkrdksntd|d|Srzrrws rrrrrcdddgiS)Nrr)rrrrws rrrs RM ""rcFt|dd}||dzf|z|dzfzfzS)NrFr{rr)rrrfrxs rrrs4As51A AE8g%! 57 77rc0tj|ddSrrrs rrrrrasph_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)rrxcZt|dd}d|cxkrdksntd|d|Srzrrws rrrrrc|jddk(r|dS|jddk(r|d|dddgddgffS|jddk(r$|d|dddgddgf|dddgddggddgddggffSyNrr).rrr}.rrTrs rrr " 9~ " 9~s3AA#6777 " IC!Q!Q$7 8 q!fq!f%AA'77 8: : raXsph_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 cZt|dd}d|cxkrdksntd|d|S)NrxFr{rr}z=diff_n is currently only implemented for orders 2, received: rrrws rrr=rrcdddgdgziS)Nrr)rrrrrws rrrHs RH// 00rc |d}t|tjr|dkr td|dzdt |zdzft j ||z|dz|dzfzfS)Nrxrrrr}r)rrr phi_shaperfrrxs rrrMsw H F a)) *q1u<== UAAJN #b&9&9+y&Q Q !VaZ  ! ##rc|jddk(r|dS|jddk(r|d|dddgddgffS|jddk(r$|d|dddgddgf|dddgddggddgddggffSyrrrs rrrXrr)r$rnumpyr"_input_validationr_special_ufuncsrrrr _gufuncsr r r r __all__rrDrrNrHrLrFrrrrs2::;; ssl @E#L&&#'#  $!!"22)3)00D1D**#+#$HE!M'T ../((#)#" E!$## $ 22344-5-22 I3 I,,#-#8= D    ""### "..#/#,,8-8 &&#'#=z#1@ F  "" :# : #1"..1/1,,#-#&& :' :r