Ë
    üÇ:jú1  ã                   óÒ   — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ d d	lmZmZ d d
lZd„ Z G d„ de
«      Z G d„ dej.                  e	«      Zd„ Zy
)é    )Útypeof)Útypes)ÚGUFuncBuilder)Úparse_signature)Ú	UfuncBaseÚUfuncLowererBase)Úufunc_find_matching_loop)Ú	serializeÚerrors)Únpydecl)Ú	signatureÚAbstractTemplateNc                 ó€   ‡ — ddl m}  G ˆ fd„d|j                  «      }|xj                  ‰ j                  z  c_        |S )Nr   ©Únpyimplc                   ó>   •‡ — e Zd ZdZW °Zˆ fd„Zˆ fd„Zˆ fd„Zˆ xZS )ú(make_gufunc_kernel.<locals>.GUFuncKernelzÊ
        npyimpl._Kernel subclass responsible for lowering a gufunc kernel
        (element-wise function) inside a broadcast loop (which is
        generated by npyimpl.numpy_gufunc_kernel()).
        c                 óÂ   •— t         ‰| �  |||«       | j                  j                  |j                  «      }| j                  j                  |«      \  | _        | _        y ©N)ÚsuperÚ__init__ÚdufuncÚ_get_ewise_dtypesÚargsÚfind_ewise_functionÚ	inner_sigÚcres)ÚselfÚcontextÚbuilderÚ	outer_sigÚewise_typesÚ	__class__s        €új/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/numba/np/ufunc/gufunc.pyr   z1make_gufunc_kernel.<locals>.GUFuncKernel.__init__   sL   ø€ Ü‰GÑ˜W g¨yÔ9ØŸ+™+×7Ñ7¸	¿¹ÓGˆKØ(,¯©×(GÑ(GØó)Ñ%ˆDŒN˜D�Ió    c                 óÄ   •— t        |t        j                  «      r5t        |t        j                  «      st        ‰| �  ||j
                  |«      S t        ‰| �  |||«      S r   )Ú
isinstancer   ÚArrayr   ÚcastÚdtype)r   ÚvalÚfromtyÚtotyr#   s       €r$   r)   z-make_gufunc_kernel.<locals>.GUFuncKernel.cast   sI   ø€ ä˜&¤%§+¡+Ô.Ü˜t¤U§[¡[Ô1Ü‘w‘| C¨¯©°tÓ<Ð<Ü‘7‘<  V¨TÓ2Ð2r%   c                 óÖ   •— | j                   j                  rd}t        j                  |«      ‚| j                  j                  | j                   j                  f«       t        ‰| �   |Ž S )NzCCalling a guvectorize function in object mode is not supported yet.)	r   Ú
objectmoder   ÚNumbaRuntimeErrorr   Úadd_linking_libsÚlibraryr   Úgenerate)r   r   Úmsgr#   s      €r$   r3   z1make_gufunc_kernel.<locals>.GUFuncKernel.generate%   sW   ø€ Ø�y‰y×#Ò#ð(�ä×.Ñ.¨sÓ3Ð3Ø�L‰L×)Ñ)¨4¯9©9×+<Ñ+<Ð*>Ô?Ü‘7Ñ# TÐ*Ð*r%   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r)   r3   Ú__classcell__)r#   Ú_dufuncs   @€r$   ÚGUFuncKernelr      s#   ù„ ñ	ñ
 ˆô	ô	3÷	+ð 	+r%   r;   )Únumba.npr   Ú_Kernelr5   )r:   r   r;   s   `  r$   Úmake_gufunc_kernelr>      s5   ø€ Ý ö+�w—‘ô +ð: ×Ò˜W×-Ñ-Ñ-ÕØÐr%   c                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚGUFuncLowererzHCallable class responsible for lowering calls to a specific gufunc.
    c                 óP   •— ddl m} t        ‰| �  |t        |j
                  «       y )Nr   r   )r<   r   r   r   r>   Únumpy_gufunc_kernel)r   Úgufuncr   r#   s      €r$   r   zGUFuncLowerer.__init__4   s!   ø€ Ý$Ü‰Ñ˜Ü+Ø ×4Ñ4õ	6r%   )r5   r6   r7   r8   r   r9   )r#   s   @r$   r@   r@   1   s   ø„ ñ÷6ð 6r%   r@   c                   ó”   — e Zd ZdZ	 	 dd„Zd„ Zd„ Zed„ «       Zd„ Z	dd„Z
d	„ Zd
„ Zd„ Zd„ Zdd„Zd„ Zed„ «       Zd„ Zd„ Zd„ Zd„ Zy)ÚGUFunczÊ
    Dynamic generalized universal function (GUFunc)
    intended to act like a normal Numpy gufunc, but capable
    of call-time (just-in-time) compilation of fast loops
    specialized to inputs.
    Nc                 óš  — |€i }d | _         d| _        || _        || _        t	        ||||||«      | _        | j
                  j                  j                  | _        | j
                  j                  j                  | _        | j
                  j                  | _
        | j                  | j                  «       t        j                  | |«       y )NF)ÚufuncÚ_frozenÚ_is_dynamicÚ	_identityr   Úgufunc_builderÚpy_funcr5   r8   Únb_funcÚ_dispatcherÚ_initializeÚ	functoolsÚupdate_wrapper)r   rL   r   ÚidentityÚcacheÚ
is_dynamicÚtargetoptionsÚwritable_argss           r$   r   zGUFunc.__init__C   s³   € àÐ ØˆMØˆŒ
ØˆŒØ%ˆÔØ!ˆŒô
 ,Ø�Y ¨%°ÀóOˆÔð ×+Ñ+×3Ñ3×<Ñ<ˆŒØ×*Ñ*×2Ñ2×:Ñ:ˆŒØ×.Ñ.×6Ñ6ˆÔØ×Ñ˜×)Ñ)Ô*Ü× Ñ   wÕ/r%   c                 ó„   — | j                  «        | j                  «        t        | «      | _        | j	                  «        y r   )Úbuild_ufuncÚ_install_typer@   Ú	_lower_meÚ_install_cg)r   Ú
dispatchers     r$   rO   zGUFunc._initializeX   s2   € Ø×ÑÔØ×ÑÔÜ& tÓ,ˆŒØ×ÑÕr%   c                 óú   — | j                   }t        |j                  |j                  | j                  |j
                  | j                  |j                  |j                  |j                  | j                  ¬«	      }|S )N)	rL   r   rR   rS   rT   rU   rV   ÚtypesigsÚfrozen)rK   ÚdictrL   r   rJ   rS   rI   rU   rV   Ú_sigsrH   )r   ÚgbÚdcts      r$   Ú_reduce_stateszGUFunc._reduce_states^   sc   € Ø× Ñ ˆÜØ—J‘JØ—l‘lØ—^‘^Ø—(‘(Ø×'Ñ'Ø×*Ñ*Ø×*Ñ*Ø—X‘XØ—<‘<ô

ˆð ˆ
r%   c
           	      ó‚   —  | |||||||¬«      }
|D ]  }|
j                  |«       Œ |
j                  «        |	|
_        |
S )N)rL   r   rR   rS   rT   rU   rV   )ÚaddrX   rH   )ÚclsrL   r   rR   rS   rT   rU   rV   r^   r_   r   Úsigs               r$   Ú_rebuildzGUFunc._rebuildm   sS   € ñ ˜7¨iÀ(Ø¨:Ø!.¸môMˆð ò 	ˆCØ�H‰H�S�Mð	à×ÑÔØˆŒØˆr%   c                 ó"   — d| j                   › d�S )Nz<numba._GUFunc 'z'>)r5   ©r   s    r$   Ú__repr__zGUFunc.__repr__y   s   € Ø! $§-¡- °Ð3Ð3r%   c                 óÔ   — |€ | j                   j                  j                  }t        d| j                  z   t
        ft        | | j                  ¬«      «      }|j                  | |«       y)a*  Constructs and installs a typing class for a gufunc object in the
        input typing context.  If no typing context is given, then
        _install_type() installs into the typing context of the
        dispatcher object (should be same default context used by
        jit() and njit()).
        NÚGUFuncTyping_)ÚkeyÚgeneric)	rN   ÚtargetdescrÚtyping_contextÚtyper5   r   r`   Ú_type_meÚinsert_user_function)r   Ú	typingctxÚ_ty_clss      r$   rY   zGUFunc._install_type|   s\   € ð ÐØ×(Ñ(×4Ñ4×CÑCˆIÜ�¨¯©Ñ6Ü(Ð*Ü ¨d¯m©mÔ<ó>ˆð 	×&Ñ& t¨WÕ5r%   c                 ó:   — | j                   j                  |«       y r   )rK   rf   )r   Úftys     r$   rf   z
GUFunc.addŠ   s   € Ø×Ñ×Ñ Õ$r%   c                 óD   — | j                   j                  «       | _        | S r   )rK   rX   rG   rk   s    r$   rX   zGUFunc.build_ufunc�   s   € Ø×(Ñ(×4Ñ4Ó6ˆŒ
Øˆr%   c                 ó°   — t        | j                  j                  «      }t        t	        t
        |d   «      «      t        t	        t
        |d   «      «      fS ©Nr   é   )r   rK   r   ÚtupleÚmapÚlen)r   Ú
parsed_sigs     r$   Úexpected_ndimszGUFunc.expected_ndims‘   sC   € Ü$ T×%8Ñ%8×%BÑ%BÓCˆ
Ü”cœ#˜z¨!™}Ó-Ó.´´c¼#¸zÈ!¹}Ó6MÓ0NÐOÐOr%   c                 óÀ  — |rJ ‚| j                   }| j                  j                  }| j                  «       \  }}||z   }t	        |«      sJ t	        |«      «       ‚t        |«      D ]¢  \  }}	t        |	t        j                  «      sŒ!|	j                  ||   k  sŒ4|t	        |«      k  rdnd}
|t	        |«      k  r|n|t	        |«      z
  }| j                  › d|
› d|› d|	j                  › d|› d||   › d�}t        j                  |«      ‚ t        j                  j                  |||«      }|\  }}}}| j!                  |«      \  }}|€~| j"                  rd	| › d
|› �}t        j                  |«      ‚| j%                  |«       | j!                  |«      \  }}|dk(  r'd| j                  › d
|› �}t        j                  |«      ‚|€J ‚t        t        j&                  g|¢­Ž S )zì
        Implement AbstractTemplate.generic() for the typing class
        built by gufunc._install_type().

        Return the call-site signature after either validating the
        element-wise signature or compiling for it.
        ÚInputÚOutputz: z	 operand z& does not have enough dimensions (has z, gufunc core with signature z
 requires ú)zcannot call z with types ©NNzFail to compile )rG   rK   r   r‚   r€   Ú	enumerater'   r   r(   Úndimr5   r   ÚTypingErrorr   ÚNumpy_rules_ufuncÚ_handle_inputsr   rH   Ú_compile_for_argtysÚnone)r   ÚargtysÚkwsrG   rh   Ú	inp_ndimsÚ	out_ndimsÚndimsÚidxÚargÚkindÚir4   Ú_handle_inputs_resultr"   Ú_s                   r$   rt   zGUFunc._type_me•   sñ  € ñ ˆˆwØ—
‘
ˆØ×!Ñ!×+Ñ+ˆØ#×2Ñ2Ó4Ñˆ	�9Ø˜IÑ%ˆä�6Œ{Ð&œC ›JÓ&ˆ{Ü! &Ó)ò 	.‰HˆC�Ü˜#œuŸ{™{Õ+°·±¸5À¹:Ó0EØ"%¬¨I«Ò"6‘w¸H�Ø¤ Y£Ò/‘C°S¼3¸y»>Ñ5I�à—}‘}�o R¨ v¨Y°q°cð :.Ø.1¯h©h¨Zð 8!Ø!$  Z°°c±
¨|¸1ð>ð ô ×(Ñ(¨Ó-Ð-ð	.ô !(× 9Ñ 9× HÑ HØ�6˜3ó! Ðà4Ñˆ�Q˜˜1Ø×)Ñ)¨+Ó6‰ˆˆQàˆ;ð �|Š|Ø$ T F¨,°v°hÐ?�Ü×(Ñ(¨Ó-Ð-Ø×$Ñ$ [Ô1à×-Ñ-¨kÓ:‰FˆC�Ø�lÒ"Ø(¨¯©¨°|ÀFÀ8ÐL�Ü×(Ñ(¨Ó-Ð-à�?Ð"�?äœŸ™Ð- fÒ-Ð-r%   c                 óX   —  | j                   |Ž }| j                  j                  |«       y r   )Ú_get_function_typerK   rf   )r   r�   Úreturn_typeÚfntys       r$   r�   zGUFunc._compile_for_argtysÄ   s*   € ð 'ˆt×&Ñ&¨Ð/ˆØ×Ñ×Ñ Õ%r%   c                 óf   — | j                  |j                  «      }t        |«      t        |«      k(  S r   )r   r   r~   )r   r"   rh   Údtypess       r$   Úmatch_signaturezGUFunc.match_signatureË   s*   € Ø×'Ñ'¨¯©Ó1ˆÜ�V‹}¤ kÓ 2Ñ2Ð2r%   c                 ó   — | j                   S r   )rI   rk   s    r$   rT   zGUFunc.is_dynamicÏ   s   € à×ÑÐr%   c                 óÀ   — t        d„ |«      }g }|D ]I  }t        |t        j                  «      r|j	                  |j
                  «       Œ9|j	                  |«       ŒK |S )Nc                 óP   — t        | t        j                  «      r| S t        | «      S r   )r'   r   ÚTyper   )r•   s    r$   ú<lambda>z*GUFunc._get_ewise_dtypes.<locals>.<lambda>Ô   s   € ¬
°3¼¿
¹
Ô(C € Ü˜C“[ð r%   )r   r'   r   r(   Úappendr*   )r   r   r�   ÚtysÚargtys        r$   r   zGUFunc._get_ewise_dtypesÓ   sY   € Üñ !Ø"&ó(ˆàˆØò 	"ˆEÜ˜%¤§¡Ô-Ø—
‘
˜5Ÿ;™;Õ'à—
‘
˜5Õ!ð		"ð
 ˆ
r%   c                 ó’   — t        | j                  j                  «      }t        |«      t        |d   «      t        |d   «      z   k(  S r|   )r   rK   r   r€   )r   r   r�   s      r$   Ú_num_args_matchzGUFunc._num_args_matchÞ   s>   € Ü$ T×%8Ñ%8×%BÑ%BÓCˆ
Ü�4‹yœC 
¨1¡Ó.´°ZÀ±]Ó1CÑCÑCÐCr%   c                 ó  — t        | j                  j                  «      }| j                  |«      }g }t	        |d   «      D ]S  \  }}t        |«      }|dk(  r|j                  ||   «       Œ+|j                  t        j                  ||   |d«      «       ŒU t        |d   «      }t	        |d   «      D ]B  \  }}|||z      }	t        |«      xs d}
|j                  t        j                  |	|
d«      «       ŒD t        j                  |Ž S )Nr   ÚAr}   )
r   rK   r   r   rˆ   r€   r¦   r   r(   rŽ   )r   r   r�   r"   Úlr”   Úsig_dimr‰   ÚoffsetÚrettyÚret_ndims              r$   r›   zGUFunc._get_function_typeâ   sý   € Ü$ T×%8Ñ%8×%BÑ%BÓCˆ
à×,Ñ,¨TÓ2ˆð ˆÜ% j°¡mÓ4ò 	C‰LˆC�Ü�w“<ˆDØ�qŠyØ—‘˜ SÑ)Õ*à—‘œŸ™ [°Ñ%5°t¸SÓAÕBð	Cô �Z ‘]Ó#ˆä% j°¡mÓ4ò 	8‰LˆC�Ø  f¡Ñ-ˆEÜ˜7“|Ò( qˆHØ�H‰H”U—[‘[ ¨°#Ó6Õ7ð	8ô
 �z‰z˜1ˆ~Ðr%   c                 óF  — | j                   s| j                  s<|r(t        |d   «      r |d   j                  | dg|¢­i |¤ŽS  | j                  |i |¤ŽS d|v r||j                  d«      fz  } | j                  |Ž du rd| j                  › d�}t        |«      ‚| j                  |«      }| j                  rt        | j                  |«      sD| j                  |«      dk7  s  | j                  |Ž }| j                  |«       | j                  «         | j                  |i |¤ŽS )Nr   Ú__call__ÚoutFz Too few arguments for function 'z'. Note that the pattern `out = gufunc(Arg1, Arg2, ..., ArgN)` is not allowed. Use `gufunc(Arg1, Arg2, ..., ArgN, out) instead.r‡   )rH   rT   Ú_is_array_wrapperÚ__array_ufunc__rG   Úpoprª   r5   Ú	TypeErrorr   r	   r   r›   rf   rX   )r   r   Úkwargsr4   Úewiserh   s         r$   r³   zGUFunc.__call__ú   s>  € ð �<Š<˜tŸšñ
 Ô)¨$¨q©'Ô2Ø.�t˜A‘w×.Ñ.Ø˜*ðØ'+òØ/5ñð ð "�t—z‘z 4Ð2¨6Ñ2Ð2Ø�f‰_à�V—Z‘Z Ó&Ð(Ñ(ˆDàˆ4×Ñ Ð&¨%Ñ/ð
 3°4·=±=°/ð Bð ð ô
 ˜C“.Ð ð ×&Ñ& tÓ,ˆØ—
’
Ô7¸¿
¹
ÀEÔJð ×+Ñ+¨EÓ2°lÒBØ-�d×-Ñ-¨tÐ4�Ø—‘˜”Ø×ÑÔàˆt�z‰z˜4Ð* 6Ñ*Ð*r%   )NNFN© r   )r5   r6   r7   r8   r   rO   rd   Úclassmethodri   rl   rY   rf   rX   r‚   rt   r�   r    ÚpropertyrT   r   rª   r›   r³   r»   r%   r$   rE   rE   ;   s‡   „ ñð AEØEGó0ò*òð ñ	ó ð	ò4ó6ò%òòPò-.ó^&ò3ð ñ ó ð ò	òDòó0(+r%   rE   c                 ó\   — t        | t        «       xr t        | d«      xr t        | d«      S )ad  Return True if obj wraps around numpy or another numpy-like library
    and is likely going to apply the ufunc to the wrapped array; False
    otherwise.

    At the moment, this returns True for

    - dask.array.Array
    - dask.dataframe.DataFrame
    - dask.dataframe.Series
    - xarray.DataArray
    - xarray.Dataset
    - xarray.Variable
    - pint.Quantity
    - other potential wrappers around dask array or dask dataframe

    We may need to add other libraries that pickle ufuncs from their
    __array_ufunc__ method in the future.

    Note that the below test is a lot more naive than
    `dask.base.is_dask_collection`
    (https://github.com/dask/dask/blob/5949e54bc04158d215814586a44d51e0eb4a964d/dask/base.py#L209-L249),  # noqa: E501
    because it doesn't need to find out if we're actually dealing with
    a dask collection, only that we're dealing with a wrapper.
    Namely, it will return True for a pint.Quantity wrapping around a plain float, a
    numpy.ndarray, or a dask.array.Array, and it's OK because in all cases
    Quantity.__array_ufunc__ is going to forward the ufunc call inwards.
    Ú__dask_graph__r¶   )r'   rs   Úhasattr)Úobjs    r$   rµ   rµ   %  s6   € ô: �sœDÓ!Ð!ò 	,Ü�CÐ)Ó*ò	,ä�CÐ*Ó+ðr%   )Únumbar   Ú
numba.corer   Únumba.np.ufunc.ufuncbuilderr   Únumba.np.ufunc.sigparser   Únumba.np.ufunc.ufunc_baser   r   Únumba.np.numpy_supportr	   r
   r   Únumba.core.typingr   Únumba.core.typing.templatesr   r   rP   r>   r@   ÚReduceMixinrE   rµ   r»   r%   r$   ú<module>rË      sR   ðÝ Ý Ý 5Ý 3ß AÝ ;ß (Ý %ß CÛ ò!ôH6Ð$ô 6ôg+ˆY×"Ñ" Iô g+óT r%   