B
     \}                 @   s  d dl mZmZmZ d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZmZmZmZmZmZ d dlmZ d dlmZ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!m"Z"m#Z# G dd de$Z%G dd de$Z&G dd de&Z'e(ddZ)G dd de$Z*G dd dej+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/G d d! d!e/Z0e1e%e2d"d# ej3D  dS )$    )print_functiondivisionabsolute_importN)_dispatchercompilerutilstypesconfigerrors)default_type_manager)sigutils	serializetyping)fold_arguments)Purposetypeof)get_code_object)create_bound_methodreraise   )	NullCacheFunctionCachec               @   s,   e Zd ZdZdd Zdd Zedd ZdS )	
OmittedArgzC
    A placeholder for omitted arguments with a default value.
    c             C   s
   || _ d S )N)value)selfr    r   /lib/python3.7/site-packages/numba/dispatcher.py__init__   s    zOmittedArg.__init__c             C   s   d| j f S )Nzomitted arg(%r))r   )r   r   r   r   __repr__   s    zOmittedArg.__repr__c             C   s   t | jS )N)r   Omittedr   )r   r   r   r   _numba_type_"   s    zOmittedArg._numba_type_N)__name__
__module____qualname____doc__r   r   propertyr    r   r   r   r   r      s   r   c               @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )_FunctionCompilerc             C   s0   || _ || _|| _|| _t| j | _|| _d S )N)py_functargetdescrtargetoptionslocalsr   pysignaturepysigpipeline_class)r   r'   r(   r)   r*   r-   r   r   r   r   )   s    z_FunctionCompiler.__init__c             C   s6   dd }dd }dd }t | j|||||}| j|fS )z
        Given positional and named argument types, fold keyword arguments
        and resolve defaults by inserting types.Omitted() instances.

        A (pysig, argument types) tuple is returned.
        c             S   s   |S )Nr   )indexparamr   r   r   r   normal_handler9   s    z=_FunctionCompiler.fold_argument_types.<locals>.normal_handlerc             S   s
   t |S )N)r   r   )r.   r/   defaultr   r   r   default_handler;   s    z>_FunctionCompiler.fold_argument_types.<locals>.default_handlerc             S   s
   t |S )N)r   ZTuple)r.   r/   valuesr   r   r   stararg_handler=   s    z>_FunctionCompiler.fold_argument_types.<locals>.stararg_handler)r   r,   )r   argskwsr0   r2   r4   r   r   r   fold_argument_types2   s    
z%_FunctionCompiler.fold_argument_typesc          
   C   sp   t  }| jj|| j | |}| |i }t j| jj	| jj
||||| j| jd}|jd k	rl|jsl|j|S )N)r5   return_typeflagsr*   r-   )r   ZFlagsr(   ZoptionsZparse_as_flagsr)   _customize_flags_get_implementationZcompile_extratyping_contexttarget_contextr*   r-   typing_errorenable_pyobject)r   r5   r8   r9   implcresr   r   r   compileG   s    


z_FunctionCompiler.compilec             C   s   t | jS )N)r   #_get_function_globals_for_reductionr'   )r   r   r   r   get_globals_for_reductionX   s    z+_FunctionCompiler.get_globals_for_reductionc             C   s   | j S )N)r'   )r   r5   r6   r   r   r   r;   [   s    z%_FunctionCompiler._get_implementationc             C   s   |S )Nr   )r   r9   r   r   r   r:   ^   s    z"_FunctionCompiler._customize_flagsN)	r!   r"   r#   r   r7   rB   rD   r;   r:   r   r   r   r   r&   '   s   	r&   c                   s,   e Zd Z fddZdd Zdd Z  ZS )_GeneratedFunctionCompilerc                s$   t t| ||||| t | _d S )N)superrE   r   setimpls)r   r'   r(   r)   r*   r-   )	__class__r   r   r   d   s    
z#_GeneratedFunctionCompiler.__init__c             C   s   t | jS )N)r   rC   r'   )r   r   r   r   rD   j   s    z4_GeneratedFunctionCompiler.get_globals_for_reductionc       	      C   s   | j ||}t| j }t|}t|jt|jk}|rxVt|j |j D ]<\}}|j|jks|j|jks|j	|j
k	rR|j	|j	krRd}qRW |std|||f | j| |S )NFz\generated implementation %s should be compatible with signature '%s', but has signature '%s')r'   r   r+   len
parameterszipr3   namekindr1   empty	TypeErrorrH   add)	r   r5   r6   r@   r,   ZimplsigokZpyparamZ	implparamr   r   r   r;   o   s"    
z._GeneratedFunctionCompiler._get_implementation)r!   r"   r#   r   rD   r;   __classcell__r   r   )rI   r   rE   b   s   rE   _CompileStats)
cache_path
cache_hitscache_missesc               @   s4   e Zd ZdZdd Zdd Zdd Zdd	 ZeZd
S )_CompilingCounterzQ
    A simple counter that increment in __enter__ and decrement in __exit__.
    c             C   s
   d| _ d S )Nr   )counter)r   r   r   r   r      s    z_CompilingCounter.__init__c             C   s    | j dkst|  j d7  _ d S )Nr   r   )rY   AssertionError)r   r   r   r   	__enter__   s    z_CompilingCounter.__enter__c             O   s    |  j d8  _ | j dkstd S )Nr   r   )rY   rZ   )r   r5   kwargsr   r   r   __exit__   s    z_CompilingCounter.__exit__c             C   s
   | j dkS )Nr   )rY   )r   r   r   r   __bool__   s    z_CompilingCounter.__bool__N)	r!   r"   r#   r$   r   r[   r]   r^   Z__nonzero__r   r   r   r   rX      s   rX   c               @   s   e Zd ZdZdZdd Zdd Zdd Zed	d
 Z	edd Z
d1ddZdd Zdd Zdd Zdd Zedd Zdd Zd2ddZd3dd Zd4d!d"Zd5d#d$Zd6d%d&Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 ZdS )7_DispatcherBasez;
    Common base class for dispatcher Implementations.
    r'   c             C   s   t | _t | _|| _t|| _| j| _t	|j
}| jjp<d}t	dd |D }yt|j
 d }	W n tk
r~   d}
Y nX |	j|	jk}
tj| | j || j||||
|	 |j| _t | _t| |   d S )Nr   c             s   s   | ]}t |V  qd S )N)r   ).0valr   r   r   	<genexpr>   s    z+_DispatcherBase.__init__.<locals>.<genexpr>F)r   Z_tmcollectionsOrderedDict	overloadsr'   r   Z	func_code__code__tuplerK   __defaults__listr3   
IndexErrorrN   ZVAR_POSITIONALr   
Dispatcherr   Zget_pointer
_fold_argsr$   docrX   _compiling_counterr   finalize_make_finalizer)r   	arg_countr'   r,   can_fallbackexact_match_requiredZargnamesZdefault_valuesZdefargsZlastargZhas_starargr   r   r   r      s,    



z_DispatcherBase.__init__c             C   s   |    | j  d S )N)Z_clearrf   clear)r   r   r   r   _reset_overloads   s    z _DispatcherBase._reset_overloadsc                s$   | j  | jtjf fdd	}|S )zq
        Return a finalizer function that will release references to
        related compiled functions.
        c          	      sF   |  r
d S x6   D ]*}y|j W q tk
r<   Y qX qW d S )N)r3   Zremove_user_functionentry_pointKeyError)shutting_downrA   )rf   	targetctxr   r   	finalizer   s    z2_DispatcherBase._make_finalizer.<locals>.finalizer)rf   rz   r   ry   )r   r{   r   )rf   rz   r   rq      s    z_DispatcherBase._make_finalizerc             C   s
   t | jS )zA
        Returns a list of compiled function signatures.
        )rj   rf   )r   r   r   r   
signatures   s    z_DispatcherBase.signaturesc             C   s   dd | j  D S )Nc             S   s   g | ]}|j s|js|jqS r   )
objectmode
interpmode	signature)r`   rA   r   r   r   
<listcomp>   s    z7_DispatcherBase.nopython_signatures.<locals>.<listcomp>)rf   r3   )r   r   r   r   nopython_signatures   s    z#_DispatcherBase.nopython_signaturesTc             C   s"   |rt | jdkst| | _dS )z@Disable the compilation of new signatures at call time.
        r   N)rJ   r|   rZ   _can_compile)r   ra   r   r   r   disable_compile   s    z_DispatcherBase.disable_compilec             C   s>   t |jj}dd |D }| ||j|j|j || j|< d S )Nc             S   s   g | ]
}|j qS r   )_code)r`   ar   r   r   r      s    z0_DispatcherBase.add_overload.<locals>.<listcomp>)rh   r   r5   Z_insertrw   r}   r~   rf   )r   rA   r5   sigr   r   r   add_overload   s    z_DispatcherBase.add_overloadc             C   s   | j ||S )N)	_compilerr7   )r   r5   r6   r   r   r   r7      s    z#_DispatcherBase.fold_argument_typesc             C   sZ   | j ||\}}i }| jr*| t| | jj}d|}tj	||| j
d}||||fS )z
        Get a typing.ConcreteTemplate for this dispatcher and the given
        *args* and *kws* types.  This allows to resolve the return type.

        A (template, pysig, args, kws) tuple is returned.
        zCallTemplate({0}))keyr|   )r   r7   r   rB   rh   r'   r!   formatr   make_concrete_templater   )r   r5   r6   r,   	func_namerM   call_templater   r   r   get_call_template  s    
z!_DispatcherBase.get_call_templatec             C   s   t |\}}| jt| jS )zG
        Return the compiled function for the given signature.
        )r   normalize_signaturerf   rh   rw   )r   r   r5   r8   r   r   r   get_overload  s    z_DispatcherBase.get_overloadc             C   s   | j S )zG
        Whether a specialization is currently being compiled.
        )ro   )r   r   r   r   is_compiling$  s    z_DispatcherBase.is_compilingc             O   sF  |rt dd }g }x:|D ]2}t|tr<|t|j q|| | qW y| t	|S  t
jk
rR } zg }xt|D ]~\}}	t|	tr|	jn|	}
yt|
tj}W n4 tk
r } z||t|f W dd}~X Y qX |dkr||d|
f f qW |r8t| dddd |D   }|| ||d	 W dd}~X Y n t
jk
r } z||d
 W dd}~X Y n t
jt
jt
jfk
r } z||d W dd}~X Y n t
jk
r } z||d W dd}~X Y n\ tk
r@ } z<tjr,t|dr,t
jd }|d|j|  |W dd}~X Y nX dS )z
        For internal use.  Compile a specialized version of the function
        for the given *args* and *kws*, and return the resulting callable.
        c             S   sF   t jr&tj| }| d| j|  t jr2| ntt	| | d dS )z{
            Rewrite and raise Exception `e` with help supplied based on the
            specified issue_type.
             N)
r	   	SHOW_HELPr
   error_extraspatch_messagejoinr5   ZFULL_TRACEBACKSr   type)eZ
issue_typehelp_msgr   r   r   error_rewrite2  s    
z8_DispatcherBase._compile_for_args.<locals>.error_rewriteNz'cannot determine Numba type of value %rzC

This error may have been caused by the following argument(s):
%s

c             s   s   | ]\}}d ||f V  qdS )z- argument %d: %sNr   )r`   ierrr   r   r   rb   Z  s   z4_DispatcherBase._compile_for_args.<locals>.<genexpr>r   Zunsupported_errorZinterpreterZconstant_inferencer   Z
reportabler   ) rZ   
isinstancer   appendr   r   r   typeof_pyvalrB   rh   r
   TypingError	enumerater   r   argument
ValueErrorstrrstripr   r   ZUnsupportedErrorZNotDefinedErrorZRedefinedErrorZVerificationErrorZConstantInferenceError	Exceptionr	   r   hasattrr   r5   )r   r5   r6   r   Zargtypesr   r   Zfailed_argsr   argra   tpZ
typeof_excmsgr   r   r   r   _compile_for_args+  sR    

$




z!_DispatcherBase._compile_for_argsNc                s4   |d k	r j | j}| S t fdd jD S )Nc             3   s   | ]}|  |fV  qd S )N)inspect_llvm)r`   r   )r   r   r   rb   x  s    z/_DispatcherBase.inspect_llvm.<locals>.<genexpr>)rf   libraryZget_llvm_strdictr|   )r   r   libr   )r   r   r   s  s    z_DispatcherBase.inspect_llvmc                s4   |d k	r j | j}| S t fdd jD S )Nc             3   s   | ]}|  |fV  qd S )N)inspect_asm)r`   r   )r   r   r   rb     s    z._DispatcherBase.inspect_asm.<locals>.<genexpr>)rf   r   Zget_asm_strr   r|   )r   r   r   r   )r   r   r   z  s    z_DispatcherBase.inspect_asmc             K   s   | dd}| dd}|s|dkr*tj}xt| jD ]F\}}td| jj|f |d td|d t|j	|d td	|d q8W n(|dk	rt
d
ddlm} || |dS dS )a"  
        print or return annotated source with Numba intermediate IR

        Pass `pretty=True` to attempt color highlighting, and HTML rendering in
        Jupyter and IPython by returning an Annotate Object. `file` must be
        None if used in conjunction with `pretty=True`.
        prettyFstyler1   Nz%s %s)filezP--------------------------------------------------------------------------------zP================================================================================z$`file` must be None if `pretty=True`r   )Annotate)r   )getsysstdoutr   Z	iteritemsrf   printr'   r!   type_annotationr   Zpretty_annotater   )r   r   r\   r   r   ZverZresr   r   r   r   inspect_types  s    z_DispatcherBase.inspect_typesc                sh   |dk	rN j | }|j}dkr*|jj}ndkr<|jj}n|jj}||S t fdd jD S )a  
        For inspecting the CFG of the function.

        By default the CFG of the user function is showed.  The *show_wrapper*
        option can be set to "python" or "cfunc" to show the python wrapper
        function or the *cfunc* wrapper function, respectively.
        NZpythonZcfuncc             3   s    | ]}| j |d fV  qdS ))show_wrapperN)inspect_cfg)r`   r   )r   r   r   r   rb     s   z._DispatcherBase.inspect_cfg.<locals>.<genexpr>)	rf   r   fndescZllvm_cpython_wrapper_nameZllvm_cfunc_wrapper_nameZmangled_nameZget_function_cfgr   r|   )r   r   r   rA   r   fnamer   )r   r   r   r     s    



z_DispatcherBase.inspect_cfgc                s4   |dk	r j | }|j S t fdd jD S )z
        Gets the annotation information for the function specified by
        signature. If no signature is supplied a dictionary of signature to
        annotation information is returned.
        Nc             3   s   | ]}|  |fV  qd S )N)Zannotate)r`   r   )r   r   r   rb     s    z6_DispatcherBase.get_annotation_info.<locals>.<genexpr>)rf   r   Zannotate_rawr   r|   )r   r   rA   r   )r   r   get_annotation_info  s    

z#_DispatcherBase.get_annotation_infoc                sD   |rt dt fdd|D } j} jj j|||dd dS )z8
        Callback for the C _Dispatcher object.
        zkwargs not handledc                s   g | ]}  |qS r   )r   )r`   r   )r   r   r   r     s    z6_DispatcherBase._explain_ambiguous.<locals>.<listcomp>F)Zallow_ambiguousN)rZ   rh   r   	typingctxZresolve_overloadr'   )r   r5   r6   sigsr   )r   r   _explain_ambiguous  s
    z"_DispatcherBase._explain_ambiguousc                s>   |rt d fdd|D }ddtt| }t|dS )z8
        Callback for the C _Dispatcher object.
        zkwargs not handledc                s   g | ]}  |qS r   )r   )r`   r   )r   r   r   r     s    z;_DispatcherBase._explain_matching_error.<locals>.<listcomp>z.No matching definition for argument type(s) %sz, N)rZ   r   mapr   rP   )r   r5   r6   r   r   )r   r   _explain_matching_error  s
    z'_DispatcherBase._explain_matching_errorc                sN   |rt d fdd|D }d}x& jD ]} j||j}|r*d}q*W |S )z
        Callback for the C _Dispatcher object.
        Search for approximately matching signatures for the given arguments,
        and ensure the corresponding conversions are registered in the C++
        type manager.
        zkwargs not handledc                s   g | ]}  |qS r   )r   )r`   r   )r   r   r   r     s    z;_DispatcherBase._search_new_conversions.<locals>.<listcomp>FT)rZ   r   r   Zinstall_possible_conversionsr5   )r   r5   r6   foundr   Zconvr   )r   r   _search_new_conversions  s    z'_DispatcherBase._search_new_conversionsc             C   s   dt | j| jf S )Nz%s(%s))r   r!   r'   )r   r   r   r   r     s    z_DispatcherBase.__repr__c             C   s>   yt |tj}W n tk
r*   tj}Y nX |dkr:tj}|S )z
        Resolve the Numba type of Python value *val*.
        This is called from numba._dispatcher as a fallback if the native code
        cannot decide the type.
        N)r   r   r   r   r   Zpyobject)r   ra   r   r   r   r   r     s    z_DispatcherBase.typeof_pyval)T)N)N)N)NN)N)r!   r"   r#   r$   	__numba__r   rv   rq   r%   r|   r   r   r   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r_      s0   !
H





r_   c               @   s   e Zd ZdZdZeedZe	 Z
ejejdZdZdZi i dejfdd	Zed
d Zdd Zd#ddZdd Zedd Zedd Zdd Zejdd Zdd Z edd Z!d$dd Z"d%d!d"Z#dS )&rl   z
    Implementation of user-facing dispatcher objects (i.e. created using
    the @jit decorator).
    This is an abstract base class. Subclasses should define the targetdescr
    class attribute.
    T)directZ	generated)maxlenNr'   r   c       
      C   s   | j j| _| j j| _t|}t|j}|	dd }t
j| ||||dd t| | || _|| _t | _| j| }	|| _|	|| j |||| _t | _t | _t| | _| j| | j dS )a  
        Parameters
        ----------
        py_func: function object to be compiled
        locals: dict, optional
            Mapping of local variable names to Numba types.  Used to override
            the types deduced by the type inference engine.
        targetoptions: dict, optional
            Target-specific config options.
        impl_kind: str
            Select the compiler mode for `@jit` and `@generated_jit`
        pipeline_class: type numba.compiler.BasePipeline
            The compiler pipeline type.
        ZnopythonF)rt   N)r(   r<   r   r=   rz   r   r+   rJ   rK   r   r_   r   	functoolsupdate_wrapperr)   r*   r   _cache_impl_kinds
_impl_kindr   rd   Counter_cache_hits_cache_missesr   rl   Z_typeZinsert_global)
r   r'   r*   r)   	impl_kindr-   r,   rr   rs   Zcompiler_classr   r   r   r     s&    






zDispatcher.__init__c             C   s
   t | S )N)r   rl   )r   r   r   r   r    5  s    zDispatcher._numba_type_c             C   s   t | j| _d S )N)r   r'   r   )r   r   r   r   enable_caching9  s    zDispatcher.enable_cachingc             C   s   |dkr| S t | |S dS )z9Allow a JIT function to be bound as a method to an objectN)r   )r   objZobjtyper   r   r   __get__<  s    zDispatcher.__get__c          	   C   s^   | j rg }ndd | j D }| j }tj| jt| j	t
| j|| j| j| j| j |ffS )z
        Reduce the instance for pickling.  This will serialize
        the original function as well the compilation options and
        compiled signatures, but not the compiled code itself.
        c             S   s   g | ]
}|j qS r   )r   )r`   Zcrr   r   r   r   L  s    z)Dispatcher.__reduce__.<locals>.<listcomp>)r   rf   r3   r   rD   r   Z_rebuild_reductionrI   r   _uuidZ_reduce_functionr'   r*   r)   r   )r   r   Zglobsr   r   r   
__reduce__C  s    
zDispatcher.__reduce__c             C   sd   y
| j | S  tk
r   Y nX tj| }| ||||}	|	| x|D ]}
|	|
 qHW ||	_|	S )zK
        Rebuild an Dispatcher instance after it was __reduce__'d.
        )_memorx   r   Z_rebuild_function	_set_uuidrB   r   )clsuuidZfunc_reducedr*   r)   r   Zcan_compiler   r'   r   r   r   r   r   _rebuildT  s    



zDispatcher._rebuildc             C   s(   | j }|dkr$tt }| | |S )z
        An instance-specific UUID, to avoid multiple deserializations of
        a given instance.

        Note this is lazily-generated, for performance reasons.
        N)_Dispatcher__uuidr   r   Zuuid1r   )r   ur   r   r   r   g  s
    
zDispatcher._uuidc             C   s.   | j d kst|| _ | | j|< | j|  d S )N)r   rZ   r   _recentr   )r   r   r   r   r   r   u  s    
zDispatcher._set_uuidc          	   C   s   | j std| j t|\}}| jt|}|d k	rB|jS | j	
|| j}|d k	r| j|  d7  < |js|js| j|j|j|jg | | |jS | j|  d7  < | j||}| | | j	|| |jS Q R X d S )Nzcompilation disabledr   )r   RuntimeErrorro   r   r   rf   r   rh   rw   r   Zload_overloadrz   r   r}   r~   Zinsert_user_functionr   r   r   r   r   rB   Zsave_overload)r   r   r5   r8   existingrA   r   r   r   rB   {  s(    


zDispatcher.compilec             C   s\   t | j}| j}|    |   | j  d| _zx|D ]}| | q:W W d|| _X dS )z2
        Recompile all signatures afresh.
        TN)rj   rf   r   rq   rv   r   flushrB   )r   r   Zold_can_compiler   r   r   r   	recompile  s    



zDispatcher.recompilec             C   s   t | jj| j| jdS )N)rU   rV   rW   )rT   r   rU   r   r   )r   r   r   r   stats  s    zDispatcher.statsr   c                s8   fdd |dk	r  | n fddj D  dS )a2  
        Print parallel diagnostic information for the given signature. If no
        signature is present it is printed for all known signatures. level is
        used to adjust the verbosity, level=1 (default) is minimal verbosity,
        and 2, 3, and 4 provide increasing levels of verbosity.
        c                s:   j |  }|jdd }|d kr,d}t||  d S )NZparfor_diagnosticsz8No parfors diagnostic available, is 'parallel=True' set?)rf   metadatar   r   dump)r   ZolZpfdiagr   )levelr   r   r   r     s    
z-Dispatcher.parallel_diagnostics.<locals>.dumpNc                s   g | ]} |qS r   r   )r`   r   )r   r   r   r     s    z3Dispatcher.parallel_diagnostics.<locals>.<listcomp>)r|   )r   r   r   r   )r   r   r   r   parallel_diagnostics  s    
zDispatcher.parallel_diagnosticsc                s0   |dk	r j | jS t fdd jD S dS )zH
        Obtain the compilation metadata for a given signature.
        Nc             3   s   | ]}| j | jfV  qd S )N)rf   r   )r`   r   )r   r   r   rb     s    z*Dispatcher.get_metadata.<locals>.<genexpr>)rf   r   r   r|   )r   r   r   )r   r   get_metadata  s    zDispatcher.get_metadata)N)Nr   )N)$r!   r"   r#   r$   rm   r&   rE   r   weakrefWeakValueDictionaryr   rd   dequer	   ZFUNCTION_CACHE_SIZEr   r   r   r   ZPipeliner   r%   r    r   r   r   classmethodr   r   r   global_compiler_lockrB   r   r   r   r   r   r   r   r   rl     s,   (

rl   c               @   s:   e Zd ZdZdZdd Zdd Zdd Zej	d	d
 Z
dS )
LiftedCodez
    Implementation of the hidden dispatcher objects used for lifted code
    (a lifted loop is really compiled as a separate function).
    Fc             C   sN   || _ d | _|| _|| _|| _|| _tj| | j j| j j	j
| j j	jddd d S )NTF)rs   rt   )func_irlifted_fromr   rz   r9   r*   r_   r   rr   Zfunc_idfuncr,   )r   r   r   rz   r9   r*   r   r   r   r     s    zLiftedCode.__init__c             C   s
   | j jjS )z5Return the starting line number of the loop.
        )r   Zlocline)r   r   r   r   get_source_location  s    zLiftedCode.get_source_locationc             C   s   dS )zPre-compile actions
        Nr   )r   r5   r8   r9   r   r   r   _pre_compile  s    zLiftedCode._pre_compilec             C   s   | j  | j}t|\}}| jt|}|d k	r:|jS | ||| | j	
 }tj| j| j||||| jd| jd	}|jd k	r|js|j| | |jS Q R X d S )Nr   )	r   rz   r   r5   r8   r9   r*   Zliftedr   )ro   r9   r   r   rf   r   rh   rw   r   r   copyr   Z
compile_irr   rz   r*   r   r>   r?   r   )r   r   r9   r5   r8   r   Zcloned_func_irrA   r   r   r   rB     s&    


zLiftedCode.compileN)r!   r"   r#   r$   rm   r   r   r   r   r   rB   r   r   r   r   r     s   r   c               @   s   e Zd Zdd ZdS )
LiftedLoopc             C   s   |j rtdd S )NzEnable looplift flags is on)Zenable_loopliftrZ   )r   r5   r8   r9   r   r   r   r     s    zLiftedLoop._pre_compileN)r!   r"   r#   r   r   r   r   r   r     s   r   c               @   s    e Zd Zedd Zdd ZdS )
LiftedWithc             C   s
   t | S )N)r   rl   )r   r   r   r   r      s    zLiftedWith._numba_type_c             C   sH   | j r| t| d}| jj}d|}tj||| jd}||||fS )z
        Get a typing.ConcreteTemplate for this dispatcher and the given
        *args* and *kws* types.  This enables the resolving of the return type.

        A (template, pysig, args, kws) tuple is returned.
        NzCallTemplate({0}))r   r|   )	r   rB   rh   r'   r!   r   r   r   r   )r   r5   r6   r,   r   rM   r   r   r   r   r     s    
zLiftedWith.get_call_templateN)r!   r"   r#   r%   r    r   r   r   r   r   r     s   r   c                   s8   e Zd Z fddZedd Zdd Zdd Z  ZS )	ObjModeLiftedWithc                sF   | dd | _tt| j|| | jjs0td| jd krBtdd S )Noutput_typesz expecting `flags.force_pyobject`z`output_types` must be provided)	popr   rF   r   r   r9   Zforce_pyobjectr   rP   )r   r5   r\   )rI   r   r   r   0  s    
zObjModeLiftedWith.__init__c             C   s
   t | S )N)r   ZObjModeDispatcher)r   r   r   r   r    8  s    zObjModeLiftedWith._numba_type_c             C   s|   |rt | | tjgt| }| jr6| t| tj	| j
f| g}d}| jj}d|}tj|||d}||||fS )z
        Get a typing.ConcreteTemplate for this dispatcher and the given
        *args* and *kws* types.  This enables the resolving of the return type.

        A (template, pysig, args, kws) tuple is returned.
        NzCallTemplate({0}))r   r|   )rZ   _legalize_arg_typesr   Zffi_forced_objectrJ   r   rB   rh   r   r   r   r'   r!   r   r   )r   r5   r6   r|   r,   r   rM   r   r   r   r   r   <  s    

z#ObjModeLiftedWith.get_call_templatec             C   s`   xZt |ddD ]J\}}t|tjr8d}t||qt|tjrd}t||qW d S )Nr   )startz>Does not support list type inputs into with-context for arg {}zBDoes not support function type inputs into with-context for arg {})r   r   r   ZListr
   r   r   rl   )r   r5   r   r   r   r   r   r   r   T  s    z%ObjModeLiftedWith._legalize_arg_types)	r!   r"   r#   r   r%   r    r   r   rS   r   r   )rI   r   r   /  s   r   c             c   s   | ]}t ||jfV  qd S )N)r   r   )r`   tr   r   r   rb   g  s    rb   )4Z
__future__r   r   r   rd   r   osZstructr   r   r   Znumbar   r   r   r   r	   r
   Znumba.typeconv.rulesr   r   r   r   Znumba.typing.templatesr   Znumba.typing.typeofr   r   Znumba.bytecoder   Z	numba.sixr   r   Zcachingr   r   objectr   r&   rE   
namedtuplerT   rX   rl   r_   r   r   r   r   Ztypeof_initr   Znumber_domainr   r   r   r   <module>   sB    ;&  X VB6