U
    hâËd~‘  ã                   @   sx  d Z ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z
mZmZ ddlmZmZ edd	d
gƒZeddƒZe d¡Ze d¡ZeZdd„ ZedƒZedƒZedƒZedƒZdZeeƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ dZ!dZ"dZ#dZ$dZ%e &eeeeeg¡Z'e (e'¡Z)G dd„ deƒZ*G d d!„ d!eƒZ+G d"d#„ d#e+ƒZ,G d$d%„ d%e+ƒZ-e,e-d&œZ.d'd(„ Z/dS ))z3
Calling conventions for Numba-compiled functions.
é    )Ú
namedtuple)ÚIterableN)Úir)ÚtypesÚcgutilsÚerrors)ÚPYOBJECTÚGENERIC_POINTERÚ	TryStatusÚin_tryÚexcinfoÚStatus)ÚcodeÚis_okÚis_noneÚis_errorÚis_stop_iterationÚis_python_excÚis_user_excÚ
excinfoptré    é@   c                 C   s   t  t| ¡S ©N)r   ÚConstantÚ	errcode_t)r   © r   úL/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/core/callconv.pyÚ
_const_int+   s    r   éÿÿÿÿéþÿÿÿéýÿÿÿé   c                   @   sl   e Zd Z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d„ Zdd„ Zdd„ Zdd„ ZdS )ÚBaseCallConvc                 C   s
   || _ d S r   )Úcontext)Úselfr#   r   r   r   Ú__init__<   s    zBaseCallConv.__init__c              	   C   sà   |t jkr|  |¡ nÆ||kr€| jj|||d�}t ||j¡}| |¡�& | j 	||j
|j¡}|  ||¡ W 5 Q R X |  |¡ n\t|t jƒsÌ||j
kr¬| jj||||j
d�}| j 	||j
|¡}|  ||¡ ntd ||¡ƒ‚d S )N)Úvalue)ZfromtyZtotyzreturning {0} for {1})r   ÚnoneÚreturn_native_noner#   Zmake_helperr   Zas_bool_bitZvalidÚif_thenZget_return_valueÚtypeÚdataÚreturn_valueÚ
isinstanceÚOptionalÚcastÚNotImplementedErrorÚformat)r$   ÚbuilderÚrettyZvaltyr&   ÚoptvalZvalidbitÚretvalr   r   r   Úreturn_optional_value?   s*    
ÿ
ÿÿz"BaseCallConv.return_optional_valuec                 C   s   |   |t¡ d S r   )Ú_return_errcode_rawÚRETCODE_NONE©r$   r2   r   r   r   r(   \   s    zBaseCallConv.return_native_nonec                 C   s   |   |t¡ d S r   )r7   ÚRETCODE_EXCr9   r   r   r   Ú
return_exc_   s    zBaseCallConv.return_excc                 C   s   |   |t¡ d S r   )r7   ÚRETCODE_STOPITr9   r   r   r   Úreturn_stop_iterationb   s    z"BaseCallConv.return_stop_iterationc                 C   s   | j j|  ¡ }| ¡ S )zQ
        Get the actual type of the return argument for Numba type *ty*.
        )r#   Údata_model_managerÚget_return_typeÚ
as_pointer)r$   ÚtyÚrestyper   r   r   r?   e   s    zBaseCallConv.get_return_typec                 C   s   |   |¡}||_|S )zS
        Initialize and return a call helper object for the given builder.
        )Ú_make_call_helperÚ_BaseCallConv__call_helper)r$   r2   Úchr   r   r   Úinit_call_helperl   s    
zBaseCallConv.init_call_helperc                 C   s   |j S r   )rD   r9   r   r   r   Ú_get_call_helpert   s    zBaseCallConv._get_call_helperc                 C   s   |  |j¡S r   )Úunserializer   )r$   r2   ÚpyapiÚstatusr   r   r   Úunpack_exceptionw   s    zBaseCallConv.unpack_exceptionc              
   C   sÞ   |j  ¡ }| |j¡�P | ¡  |  |||¡}t |t ||¡¡� | 	|¡ W 5 Q R X | 
|¡ W 5 Q R X | |j¡� | d¡ | 
|¡ W 5 Q R X | |j¡� | 
|¡ W 5 Q R X | dd¡ | 
|¡ | |¡ dS )zT
        Given a non-ok *status*, raise the corresponding Python exception.
        ZPyExc_StopIterationZPyExc_SystemErrorz*unknown error when calling native functionN)ÚfunctionÚappend_basic_blockr)   r   Z	err_clearrK   r   Z	if_likelyZis_not_nullZraise_objectÚbranchr   Zerr_set_noner   Úerr_set_stringZposition_at_end)r$   r2   rI   rJ   ZbbendÚexcr   r   r   Úraise_errorz   s&    

ÿ
ÿ
zBaseCallConv.raise_errorc                 C   s    |   |¡}|  |¡}| ||¡S )z•
        Get the decoded (unpacked) Python arguments with *argtypes*
        from LLVM function *func*.  A tuple of LLVM values is returned.
        )Úget_argumentsÚ_get_arg_packerZfrom_arguments)r$   r2   ÚargtypesÚfuncZraw_argsÚarginfor   r   r   Údecode_arguments˜   s    

zBaseCallConv.decode_argumentsc                 C   s   | j  |¡S )zF
        Get an argument packer for the given argument types.
        )r#   Zget_arg_packer)r$   rT   r   r   r   rS   ¡   s    zBaseCallConv._get_arg_packerN)Ú__name__Ú
__module__Ú__qualname__r%   r6   r(   r;   r=   r?   rF   rG   rK   rQ   rW   rS   r   r   r   r   r"   :   s   	r"   c                   @   sd   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
ddd„Zdd„ Zdd„ ZdS )ÚMinimalCallConvaª  
    A minimal calling convention, suitable for e.g. GPU targets.
    The implemented function signature is:

        retcode_t (<Python return type>*, ... <Python arguments>)

    The return code will be one of the RETCODE_* constants or a
    function-specific user exception id (>= RETCODE_USEREXC).

    Caller is responsible for allocating a slot for the return value
    (passed as a pointer in the first argument).
    c                 C   s   t ƒ S r   )Ú_MinimalCallHelperr9   r   r   r   rC   ¶   s    z!MinimalCallConv._make_call_helperc                 C   sP   |j jd }|j|jjks4tt|jƒt|jjƒfƒ‚| ||¡ |  |t¡ d S ©Nr   )	rL   Úargsr*   ÚpointeeÚAssertionErrorÚstrÚstorer7   Ú
RETCODE_OK©r$   r2   r5   Úretptrr   r   r   r,   ¹   s    ÿzMinimalCallConv.return_valueNc           
      C   s¨   |d k	r t |tƒs td|f ƒ‚|d k	r@t|tƒs@td|f ƒ‚|d k	rx| ¡ }|d kr\|}||j|jf}d |kr|d }nd }|  |¡}| 	|||¡}	|  
|t|	ƒ¡ d S )Nú-exc should be None or exception class, got %rú(exc_args should be None or tuple, got %r)Ú
issubclassÚBaseExceptionÚ	TypeErrorr-   ÚtupleÚ_raw_function_nameÚfilenameÚlinerG   Ú_add_exceptionr7   r   )
r$   r2   rP   Úexc_argsÚlocÚ	func_nameÚfnameÚlocinfoZcall_helperÚexc_idr   r   r   Úreturn_user_excÀ   s&    ÿÿ
zMinimalCallConv.return_user_excc                 C   s   |   ||j¡ d S r   )r7   r   )r$   r2   rJ   r   r   r   Úreturn_status_propagateÚ   s    z'MinimalCallConv.return_status_propagatec                 C   s    t |tƒrt|ƒ}| |¡ d S r   )r-   Úintr   Úret©r$   r2   r   r   r   r   r7   Ý   s    
z#MinimalCallConv._return_errcode_rawc              
   C   sx   |  d|t¡}|  d|t¡}| ||¡}| |¡}|  d|t¡}|  d|t¡}|  d|t¡}	t||||||	|dd�}
|
S )z?
        Given a return *code*, get a Status instance.
        ú==ú>=N©r   r   r   r   r   r   r   r   )	Úicmp_signedrc   r8   Úor_Únot_r:   r<   ÚRETCODE_USEREXCr   )r$   r2   r   Únormr'   ÚokÚerrrP   r   r   rJ   r   r   r   Ú_get_return_statusâ   s"    
ùz"MinimalCallConv._get_return_statusc                 C   s4   |   |¡}t|jƒ}|  |¡}t t|g| ¡}|S ©zQ
        Get the implemented Function type for *restype* and *argtypes*.
        )rS   ÚlistÚargument_typesr?   r   ÚFunctionTyper   ©r$   rB   rT   rV   ZresptrÚfntyr   r   r   Úget_function_typeø   s
    


z!MinimalCallConv.get_function_typeFc                 C   s>   |rt ‚|  |¡}| |  |¡dd„ |D ƒ¡ d|jd _|S )zA
        Set names and attributes of function arguments.
        c                 S   s   g | ]}d | ‘qS ©zarg.r   ©Ú.0Úar   r   r   Ú
<listcomp>	  s     z5MinimalCallConv.decorate_function.<locals>.<listcomp>z.retr   )r`   rS   Úassign_namesrR   r^   Úname)r$   Úfnr^   Úfe_argtypesÚnoaliasrV   r   r   r   Údecorate_function  s    
ÿz!MinimalCallConv.decorate_functionc                 C   s   |j dd… S )ú@
        Get the Python-level arguments of LLVM *func*.
        r!   N©r^   ©r$   rU   r   r   r   rR     s    zMinimalCallConv.get_argumentsc                 C   sŠ   |j d jj}t ||¡}| t |¡|¡ |  |¡}| ||¡}|gt	|ƒ }	| 
||	¡}
|  ||
¡}| |¡}| j |||¡}||fS )z3
        Call the Numba-compiled *callee*.
        r   )r^   r*   r_   r   Úalloca_oncerb   Úget_null_valuerS   Úas_argumentsr‡   Úcallr…   Úloadr#   Úget_returned_value)r$   r2   ÚcalleeÚrestyÚargtysr^   r3   Ú	retvaltmprV   Úrealargsr   rJ   r5   Úoutr   r   r   Úcall_function  s    

zMinimalCallConv.call_function)NNN)F)rX   rY   rZ   Ú__doc__rC   r,   rv   rw   r7   r…   rŒ   r—   rR   r§   r   r   r   r   r[   ¨   s     ÿ


r[   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r\   z´
    A call helper object for the "minimal" calling convention.
    User exceptions are represented as integer codes and stored in
    a mapping for retrieval from the caller.
    c                 C   s
   i | _ d S r   )Ú
exceptions©r$   r   r   r   r%   -  s    z_MinimalCallHelper.__init__c                 C   s"   t | jƒt }|||f| j|< |S )aV  
        Add a new user exception to this helper. Returns an integer that can be
        used to refer to the added exception in future.

        Parameters
        ----------
        exc :
            exception type
        exc_args : None or tuple
            exception args
        locinfo : tuple
            location information
        )Úlenr©   ÚFIRST_USEREXC)r$   rP   rp   rt   ru   r   r   r   ro   0  s    z!_MinimalCallHelper._add_exceptionc                 C   sF   z| j | W S  tk
r@   d| }t}|f}d}|||f Y S X dS )z÷
        Get information about a user exception. Returns a tuple of
        (exception type, exception args, location information).

        Parameters
        ----------
        id : integer
            The ID of the exception to look up
        z#unknown error %d in native functionN)r©   ÚKeyErrorÚSystemError)r$   ru   ÚmsgrP   rp   rt   r   r   r   Úget_exceptionB  s    
z _MinimalCallHelper.get_exceptionN)rX   rY   rZ   r¨   r%   ro   r°   r   r   r   r   r\   &  s   r\   é   é   é   c                   @   sæ   e Zd ZdZe d¡Zdd„ Zdd„ Zdd„ Z	d5d
d„Z
d6dd„Zdd„ Zdd„ Zdd„ Zdd„ Zd7dd„Zd8dd„Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd9d+d,„Zd-d.„ Zd/d0„ Zd1d2„ Zd:d3d4„Zd	S );ÚCPUCallConva  
    The calling convention for CPU targets.
    The implemented function signature is:

        retcode_t (<Python return type>*, excinfo **, ... <Python arguments>)

    The return code will be one of the RETCODE_* constants.
    If RETCODE_USEREXC, the exception info pointer will be filled with
    a pointer to a constant struct describing the raised exception.

    Caller is responsible for allocating slots for the return value
    and the exception info pointer (passed as first and second arguments,
    respectively).
    r!   c                 C   s   d S r   r   r9   r   r   r   rC   s  s    zCPUCallConv._make_call_helperc                 C   sP   |   |j¡}|j|jjks4tt|jƒt|jjƒfƒ‚| ||¡ |  |t¡ d S r   )	Ú_get_return_argumentrL   r*   r_   r`   ra   rb   r7   rc   rd   r   r   r   r,   v  s    ÿzCPUCallConv.return_valuec                 C   sJ   |d k	r8|  ¡ }|d kr|}||j|jf}d |kr<d }nd }|||f}|S r   )rl   rm   rn   )r$   rP   rp   rq   rr   rs   rt   r   r   r   Úbuild_excinfo_struct}  s    
z CPUCallConv.build_excinfo_structNc                 C   s´   |d k	r t |tƒs td|f ƒ‚|d k	r@t|tƒs@td|f ƒ‚|d krNtƒ }| j |¡}|  ||||¡}| |¡}|  	|j
¡}| ||¡}	|j t d¡dƒg¡}
|	 d|
¡ d S )Nrf   rg   r!   Znumba_exception_output)rh   ri   rj   r-   rk   r#   Úget_python_apir¶   Úserialize_objectÚ_get_excinfo_argumentrL   rb   ÚmoduleÚadd_metadatar   ÚIntTypeZset_metadata)r$   r2   rP   rp   rq   rr   rI   Ú	struct_gvÚexcptrrb   Úmdr   r   r   Úset_static_user_excŽ  s"    ÿÿ%
zCPUCallConv.set_static_user_excc                 C   sN   t |ddƒ}| j|||||d� |  |¡ |r>| |d ¡ n|  |t¡ d S )NZ_in_try_blockF)rp   rq   rr   Útarget)ÚgetattrrÀ   Úcheck_try_statusrN   r7   r�   )r$   r2   rP   rp   rq   rr   Ztry_infor   r   r   rv   Ç  s    
 ÿ
zCPUCallConv.return_user_excc              	   C   s*  |j }| | |¡t¡}| | |¡t¡}| || ||j¡¡}| | |¡t¡}| | |¡t	¡}	t
 ttg¡}
| |	|
 ¡ ¡}| ||g¡}t ||¡}t ||¡�H d}| d|¡ |jj}
t|
jt
jƒsä| t |
j¡¡ n| ¡  W 5 Q R X | ||¡}| jj�r&| jj  !|| ||j"¡¡ |S )Nz<Error creating Python tuple from runtime exception argumentsZPyExc_RuntimeError)#r   Úextract_valuerŸ   ÚPICKLE_BUF_IDXÚPICKLE_BUFSZ_IDXZbytes_from_string_and_sizeZsextÚ
py_ssize_tÚHASH_BUF_IDXÚUNWRAP_FUNC_IDXr   r‰   r   r	   Úbitcastr@   rž   r   Zis_nullZif_unlikelyrO   rL   Úfunction_typer-   Úreturn_typeZVoidTypery   rœ   Zret_voidZbuild_dynamic_excinfo_structr#   Z
enable_nrtÚnrtÚfreeZvoidptr)r$   r2   rI   rJ   Úexcinfo_ptrZ	picklebufZpicklebuf_szZstatic_exc_bytesZdyn_argsZfunc_ptrr‹   r”   Zpy_tupleÚfailedr¯   r   r   r   r   Úunpack_dynamic_exceptionÕ  sN     ÿ ÿ ÿ ÿ ÿ
 ÿz$CPUCallConv.unpack_dynamic_exceptionc              
   C   s°   |j }| | |¡t¡}| d|tdƒ¡}| |¡�N\}}|� |  |||¡}	|j}
W 5 Q R X |� | 	|¡}|j}W 5 Q R X W 5 Q R X | 
|j¡}| |	|
¡ | ||¡ |S )Nú>r   )r   rÄ   rŸ   ÚALLOC_FLAG_IDXr~   Úint32_tZif_elserÑ   ÚblockrH   Úphir*   Zadd_incoming)r$   r2   rI   rJ   rÏ   Z
alloc_flagÚgtZthenZ	otherwiseZdyn_excZbb_thenZ
static_excZbb_elserÖ   r   r   r   rK   	  s     ÿ
zCPUCallConv.unpack_exceptionc                 C   s\  t  t|ƒ ¡ ¡ ¡ }d|› �}||jkr6|j |¡S t t	t	g¡}t 
|||¡}|j d¡ |j d¡ | d¡}t |¡}	| j |	¡}
| ¡ }|	 |jd |¡}dd„ |D ƒ}g }| jj|	dd	�}t|ƒD ]\\}}|	 |	 |¡|¡}|
j|||d
�}|t |j¡k�r d|› d�}t |¡‚| |¡ qÎ| jj  |	|  !|	j"¡¡ |
 #|¡}|	 $|¡ |S )NZ__excinfo_unwrap_argsZnounwindZnoinlineÚ r   c                 S   s   g | ]}|d k	r|‘qS r   r   )r�   Útypr   r   r   r‘   E  s      z@CPUCallConv.emit_unwrap_dynamic_exception_fn.<locals>.<listcomp>T)Zreturn_pyobject)Úenv_managerzCannot convert native z to a Python object.)%ÚhashlibÚsha1ra   ÚencodeÚ	hexdigestÚglobalsÚgetr   r‰   r	   ÚFunctionÚ
attributesÚaddrM   Z	IRBuilderr#   r·   r@   rÊ   r^   Zget_env_managerÚ	enumeraterÄ   rŸ   Zfrom_native_valuer   rœ   r*   r   ZTypingErrorÚappendrÍ   rÎ   rµ   rL   Z
tuple_packry   )r$   rº   Zst_typeÚnb_typesÚ_hashr“   r‹   r”   Zbb_entryr2   rI   Zst_type_ptrÚst_ptrZobjsrÚ   ÚirÙ   ÚvalÚobjr¯   Útupr   r   r   Ú emit_unwrap_dynamic_exception_fn!  s>    



ÿ


ÿ

z,CPUCallConv.emit_unwrap_dynamic_exception_fnc           
   
   C   sv   |  | j |¡¡}| | jj ||¡| ¡ ¡}dd„ |D ƒ}tdƒ}t|ƒD ]$\}}	| 	|	| 
||t|ƒg¡¡ qL|S )zP
        Create an anonymous struct containing the given LLVM *values*.
        c                 S   s   g | ]}t |tjƒr|‘qS r   )r-   r   ÚValue©r�   Úargr   r   r   r‘   l  s      z4CPUCallConv.emit_wrap_args_insts.<locals>.<listcomp>r   )rÇ   r#   Úget_abi_sizeofrÊ   rÍ   Úallocater@   rÔ   rä   rb   Úgep)
r$   r2   rI   Ústruct_typerp   Úst_sizerè   ÚzeroÚidxrð   r   r   r   Úemit_wrap_args_instsa  s    þz CPUCallConv.emit_wrap_args_instsc              
   C   sL  t |tƒstd|f ƒ‚|dk	r8t|tƒs8td|f ƒ‚| j |¡}|  ||||¡}|  |j	¡}| 
| |¡¡}	t dd„ |D ƒ¡}
|  |||
|¡}|  |j|
|¡}| | j t¡¡}| | jj ||¡t¡}tdƒ}| |	t¡| |	t¡| |t¡| |t¡tt|
ƒƒf}t|ƒD ]&\}}| ||  ||t|ƒg¡¡ �q| ||¡ dS )zf
        Compute the required bits to emit an exception with dynamic (runtime)
        values
        z(exc should be an exception class, got %rNrg   c                 S   s   g | ]}t |tjƒr|j‘qS r   )r-   r   rî   r*   rï   r   r   r   r‘   ¶  s    ÿz4CPUCallConv.set_dynamic_user_exc.<locals>.<listcomp>r   )!rh   ri   rj   r-   rk   r#   r·   r¶   r¹   rL   rŸ   r¸   r   ÚLiteralStructTyperø   rí   rº   rÇ   rñ   Ú	excinfo_trÊ   rÍ   rò   Úexcinfo_ptr_trÔ   rÄ   rÅ   rÆ   r	   r«   rä   rb   ró   )r$   r2   rP   rp   ræ   rq   rr   rI   Z
excinfo_ppr½   rô   rè   Z	unwrap_fnZexc_sizeZ	excinfo_prö   Z
exc_fieldsr÷   rð   r   r   r   Úset_dynamic_user_exct  sH    
ÿÿ1
ÿ  ÿþ




ü z CPUCallConv.set_dynamic_user_excc                 C   s&   | j ||||||d� |  |t¡ dS )zF
        Same as ::return_user_exc but for dynamic exceptions
        )rq   rr   N)rü   r7   r�   )r$   r2   rP   rp   ræ   rq   rr   r   r   r   Úreturn_dynamic_user_excÎ  s
     ÿz#CPUCallConv.return_dynamic_user_excc              	   C   s@   z|j W S  tk
r:   tj|tjddd�}||_ | Y S X d S )NZ	try_stateT)r“   Úzfill)Z_CPUCallConv__eh_try_stateÚAttributeErrorr   r›   Zintp_t)r$   r2   Zptrr   r   r   Ú_get_try_state×  s       ÿzCPUCallConv._get_try_statec                 C   sJ   |   |¡}| |¡}| d|| d¡¡}|  |j¡}| |¡}t||d�S )NrÒ   r   )r   r   )r   rŸ   Zicmp_unsignedr*   r¹   rL   r
   )r$   r2   Útry_state_ptrZ	try_depthr   r   r   r   r   r   rÃ   á  s    


zCPUCallConv.check_try_statusc                 C   s6   |   |¡}| |¡}| || d¡¡}| ||¡ d S ©Nr!   )r   rŸ   rã   r*   rb   )r$   r2   r  ÚoldÚnewr   r   r   Úset_try_statusì  s    

zCPUCallConv.set_try_statusc                 C   s\   |   |¡}| |¡}| || d¡¡}| ||¡ |  |j¡}t |jj	¡}| ||¡ d S r  )
r   rŸ   Úsubr*   rb   r¹   rL   r   rœ   r_   )r$   r2   r  r  r  r   Únullr   r   r   Úunset_try_statusó  s    

zCPUCallConv.unset_try_statusc              	   C   sT   |   |¡}|  |j¡}| |j|¡ | | |j¡¡� |  ||j	¡ W 5 Q R X d S r   )
rÃ   r¹   rL   rb   r   r)   r€   r   r7   r   )r$   r2   rJ   Z	trystatusr¾   r   r   r   rw      s
    
z#CPUCallConv.return_status_propagatec                 C   s   |  |¡ d S r   )ry   rz   r   r   r   r7     s    zCPUCallConv._return_errcode_rawc              
   C   s�   |  d|t¡}|  d|t¡}|  d|t¡}|  d|t¡}| ||¡}| |¡}	|  d|t¡}
| |
|t	 
tt	j¡¡}t|||	|||
||d�}|S )zP
        Given a return *code* and *excinfoptr*, get a Status instance.
        r{   r|   r}   )r~   rc   r8   r:   r<   r   r€   r�   Úselectr   r   rû   Ú	Undefinedr   )r$   r2   r   r   r‚   r'   rP   r   rƒ   r„   r   rJ   r   r   r   r…   
  s(    
ÿùzCPUCallConv._get_return_statusc                 C   s<   |   |¡}t|jƒ}|  |¡}t t|t t¡g| ¡}|S r†   )	rS   r‡   rˆ   r?   r   r‰   r   ÚPointerTyperû   rŠ   r   r   r   rŒ   "  s    


ÿÿzCPUCallConv.get_function_typeFc                    sê   ˆ   |¡}| ˆ  |¡dd„ |D ƒ¡ ˆ  |¡}d|_| d¡ | d¡ ˆ  |¡}d|_| d¡ | d¡ |r¨ˆ  |¡}|D ]&}t|jt	j
ƒr€| d¡ | d¡ q€‡ fdd„}	tt|	|ƒƒ}
|
ræ|j d	¡}| |j |g¡¡ |S )
zU
        Set names of function arguments, and add useful attributes to them.
        c                 S   s   g | ]}d | ‘qS r�   r   rŽ   r   r   r   r‘   4  s     z1CPUCallConv.decorate_function.<locals>.<listcomp>re   Z	nocapturer–   r   c                    s(   t | tjƒs$ˆ jj}||   ¡ r$dS dS ©NTF)r-   r   ZArrayr#   r>   Zcontains_nrt_meminfo)rA   Zdmmrª   r   r   Útype_may_always_need_nrtG  s
    z?CPUCallConv.decorate_function.<locals>.type_may_always_need_nrtZnumba_args_may_always_need_nrt)rS   r’   rR   rµ   r“   Zadd_attributer¹   r-   r*   r   r  ÚanyÚmaprº   Zadd_named_metadatarã   r»   )r$   r”   r^   r•   r–   rV   ZretargZexcargr�   r  Zargs_may_always_need_nrtZnmdr   rª   r   r—   .  s8    
ÿ







ÿÿzCPUCallConv.decorate_functionc                 C   s   |j dd… S )r˜   r±   Nr™   rš   r   r   r   rR   [  s    zCPUCallConv.get_argumentsc                 C   s
   |j d S r]   r™   rš   r   r   r   rµ   a  s    z CPUCallConv._get_return_argumentc                 C   s
   |j d S r  r™   rš   r   r   r   r¹   d  s    z!CPUCallConv._get_excinfo_argumentc                 C   sâ   |   |j¡j}t ||¡}| t |¡|¡ tj|t t	¡dd�}	|  
|¡}
t|
 ||¡ƒ}||	g| }|dkrvd}n&t|tƒr”t|tƒs”t|ƒ}ntdƒ‚|j|||d�}|  ||| |	¡¡}| |¡}| j |||¡}||fS )aU  
        Call the Numba-compiled *callee*.
        Parameters:
        -----------
        attrs: LLVM style string or iterable of individual attributes, default
               is None which specifies no attributes. Examples:
               LLVM style string: "noinline fast"
               Equivalent iterable: ("noinline", "fast")
        r   )r“   Nr   z,attrs must be an iterable of strings or None)Úattrs)rµ   rË   r_   r   r›   rb   rœ   r   r  rú   rS   r‡   r�   r-   r   ra   rk   rj   rž   r…   rŸ   r#   r    )r$   r2   r¡   r¢   r£   r^   r  r3   r¤   r   rV   r¥   Z_attrsr   rJ   r5   r¦   r   r   r   r§   g  s*    ÿ

ÿ
zCPUCallConv.call_function)NNN)NNN)NN)NN)F)N)rX   rY   rZ   r¨   Ú	itertoolsÚcountZ_status_idsrC   r,   r¶   rÀ   rv   rÑ   rK   rí   rø   rü   rý   r   rÃ   r  r  rw   r7   r…   rŒ   r—   rR   rµ   r¹   r§   r   r   r   r   r´   b  sF   
  ÿ
9  ÿ
4@  ÿ
[   ÿ
	

- ÿr´   c                   @   s   e Zd Zdd„ Zddd„ZdS )Ú
ErrorModelc                 C   s
   || _ d S r   )Ú	call_conv)r$   r  r   r   r   r%   “  s    zErrorModel.__init__Nc                 C   s$   | j r| j |t||¡ dS dS d S r  )Úraise_on_fp_zero_divisionr  rv   ÚZeroDivisionError)r$   r2   rp   rq   r   r   r   Úfp_zero_division–  s    ÿzErrorModel.fp_zero_division)NN)rX   rY   rZ   r%   r  r   r   r   r   r  ‘  s   r  c                   @   s   e Zd ZdZdZdS )ÚPythonErrorModelzL
    The Python error model.  Any invalid FP input raises an exception.
    TN©rX   rY   rZ   r¨   r  r   r   r   r   r  Ÿ  s   r  c                   @   s   e Zd ZdZdZdS )ÚNumpyErrorModela6  
    In the Numpy error model, floating-point errors don't raise an
    exception.  The FPU exception state is inspected by Numpy at the
    end of a ufunc's execution and a warning is raised if appropriate.

    Note there's no easy way to set the FPU exception state from LLVM.
    Instructions known to set an FP exception can be optimized away:
        https://llvm.org/bugs/show_bug.cgi?id=6050
        http://lists.llvm.org/pipermail/llvm-dev/2014-September/076918.html
        http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20140929/237997.html
    FNr  r   r   r   r   r  ¦  s   r  )ÚpythonÚnumpyc                 C   s   t |  |jƒS )zF
    Create an error model instance for the given target context.
    )Úerror_modelsr  )Z
model_namer#   r   r   r   Úcreate_error_model»  s    r  )0r¨   Úcollectionsr   Úcollections.abcr   r  rÛ   Zllvmliter   Z
numba.corer   r   r   Znumba.core.baser   r	   r
   r   r¼   rÔ   Zint64_tr   r   rc   r:   r8   r<   r¬   r�   Úobjectr"   r[   r\   rÅ   rÆ   rÈ   rÉ   rÓ   rù   rú   r  rû   r´   r  r  r  r  r  r   r   r   r   Ú<module>   sZ   ÿ

n~2ÿ
    3þ