B
     \W              L   @   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Zd dlZd dlZd dlZd dlmZ d dlZddlT yd dlmZ W n  ek
r   d dlmZ Y nX d dlmZmZ edkrd d	lmZ nd d	lmZ ed
kZer,d dlZefZeZ e
j!Z!ej"Z"e	j#Z$eZ%dd Z&nRd dl'Z'd dl(Zee)fZe)Z e'j!Z!e"Z"dd Z%ej*dkrpdd Z$ne	j+Z$dd Z&y(d dl,m-Z. d dl,m/Z0 d dl,m1Z2 W n^ ek
r   y(d dl3m-Z. d dl3m/Z0 d dl3m1Z2 W n ek
r   edY nX Y nX yd dlm4Z4 W nV ek
rl   yd dl4Z4W n ek
rR   edY nX dd Z5e5e4_5e4j4Z4Y nX e6j7e6j8e6j9e6j:e6j;e6j<e6j=e6j>e6j?e6j@e6jAe6jBe6jCe6jDe6jEe6jFe6jGe6jHe6jIe6jJe6jKdZLe6jMe6jNe6jOe6jPe6jQe6jRe6jSe6jTe6jUe6jVe6jWe6jXdZYe6jZe6j[e6j\e6j]e6j^dZ_e6j7de6jMde6j8d e6jNd!e6j9d"e6jOd#e6j:d$e6jPd%e6j;d&e6jQd'e6j<d(e6jRd)e6j=d*e6jSd+e6j>d,e6jTd-e6j?d.e6jUd/e6j@d0e6jVd1e6jAd2e6jWd3e6jBd4e6jXd5e6jCd6e6jDd7e6jEd8e6jFd9e6jGd:e6jHd;e6jId<e6jJd=e6jKd>e6jZde6j[d e6j\d?e6j]d@e6j^dAi&Z`ejadBkZbes8e6jceLdC< e6jdeYdD< dCe`e6jc< dCe`e6jd< ebrRe6jeeLdE< e6jfeYdF< dGagdHdI ZheifdJdKZjG dLdM dMekZlG dNdO dOeZmG dPdQ dQenZoG dRdS dSekZpdTdU ZqdVdW ZrdXdY ZsG dZd[ d[ekZtd\d] Zudwd^d_ZvejwfZxed
k r4exejyf7 Zxyd d`lzm{Z{ exe{f7 ZxW n ek
r2   Y nX dadb Z|dcdd Z}dedf Z~dgdh Zdidj Zdkdl Zdmdn Zdodp ZdqZeeZeje_d drlmZ G dsdt dtZedudv dudv  ejstdS )x    )print_functiondivisionabsolute_importN)
ModuleType   )*)StringIO)	PYVERSIONMACHINE_BITS)   r   )Mapping)r   r   c             C   s    | j dk	rt| j  | dS )z[
        Erase the traceback and hanging locals from the given exception instance.
        N)__traceback__	tracebackclear_frameswith_traceback)	exc_value r   *lib/python3.7/site-packages/numba/utils.pyerase_traceback+   s    
r   c             C   s   t | S )N)ord)xr   r   r   	asbyteint:   s    r   Zwin32c             C   s@   yt | | W n* tk
r:   t | t | | Y nX d S )N)osrenameOSErrorunlink)srcdestr   r   r   file_replace?   s
    
r   c             C   s   | S )z[
        Erase the traceback and hanging locals from the given exception instance.
        r   )r   r   r   r   r   I   s    )	signature)	Signature)	Parameterz>please install the 'funcsigs' package ('pip install funcsigs'))singledispatchzJplease install the 'singledispatch' package ('pip install singledispatch')c             C   s   g }xdd | D } | s|S x:| D ]2}|d }x$| D ]}||dd kr4d}P q4W P q"W |dkrht d|| x| D ]}|d |krx|d= qxW qW dS )zMerges MROs in *sequences* to a single MRO using the C3 algorithm.

            Adapted from http://www.python.org/download/releases/2.3/mro/.

            c             S   s   g | ]}|r|qS r   r   ).0sr   r   r   
<listcomp>n   s    z_c3_merge.<locals>.<listcomp>r   r   NzInconsistent hierarchy)RuntimeErrorappend)	sequencesresults1	candidates2seqr   r   r   	_c3_mergef   s$    



r.   )+-r   z///%z**&|^z<<z>>z==z!=<z<=>z>=iszis notin)z+=z-=z*=z//=z/=z%=z**=z&=z|=z^=z<<=z>>=)r/   r0   ~notis_truer/   z+=r0   z-=r   z*=z//z//=r1   z/=r2   z%=z**z**=r3   z&=r4   z|=r5   z^=z<<z<<=z>>z>>=z==z!=r6   z<=r7   z>=r8   zis notr9   r:   r;   r<   )r      z/?z/?=@z@=Fc               C   s   da d S )NT)_shutting_downr   r   r   r   _at_shutdown   s    r@   c             C   s   |   d}|dkp|dkS )a  
    Whether the interpreter is currently shutting down.
    For use in finalizers, __del__ methods, and similar; it is advised
    to early bind this function rather than look it up when calling it,
    since at shutdown module globals may be cleared.
    r?   TN)get)globalsvr   r   r   shutting_down   s    rD   c                   sr   e Zd Zi Zdd ZdddZdd Zdd	 Zd
d Z fddZ	dd Z
dd Zdd Zdd Zdd Z  ZS )ConfigOptionsc             C   s   | j  | _d S )N)OPTIONScopy_values)selfr   r   r   __init__  s    zConfigOptions.__init__Tc             C   s$   || j krtd| || j|< d S )NzInvalid flag: %s)rF   	NameErrorrH   )rI   namevaluer   r   r   set  s    
zConfigOptions.setc             C   s   |  |d d S )NF)rN   )rI   rL   r   r   r   unset  s    zConfigOptions.unsetc             C   s   || j krtd| d S )NzInvalid flag: %s)rF   AttributeError)rI   rL   r   r   r   _check_attr  s    
zConfigOptions._check_attrc             C   s   |  | | j| S )N)rQ   rH   )rI   rL   r   r   r   __getattr__  s    
zConfigOptions.__getattr__c                s6   | drtt| || n| | || j|< d S )N_)
startswithsuperrE   __setattr__rQ   rH   )rI   rL   rM   )	__class__r   r   rV     s    

zConfigOptions.__setattr__c             C   s   dd dd | j D  S )Nz	Flags(%s)z, c             s   s&   | ]\}}|d k	rd||f V  qdS )Fz%s=%sNr   )r#   krC   r   r   r   	<genexpr>#  s   z)ConfigOptions.__repr__.<locals>.<genexpr>)joinrH   items)rI   r   r   r   __repr__"  s    zConfigOptions.__repr__c             C   s   t |  }| j |_|S )N)typerH   rG   )rI   rG   r   r   r   rG   '  s    
zConfigOptions.copyc             C   s   t |to|j| jkS )N)
isinstancerE   rH   )rI   otherr   r   r   __eq__,  s    zConfigOptions.__eq__c             C   s
   | |k S )Nr   )rI   r_   r   r   r   __ne__/  s    zConfigOptions.__ne__c             C   s   t tt| j S )N)hashtuplesortedrH   r[   )rI   r   r   r   __hash__2  s    zConfigOptions.__hash__)T)__name__
__module____qualname__rF   rJ   rN   rO   rQ   rR   rV   r\   rG   r`   ra   re   __classcell__r   r   )rW   r   rE     s   
rE   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )	SortedMapzImmutable
    c             C   sH   g | _ i | _x6tt|D ]&\}\}}|| j|< | j ||f qW d S )N)rH   _index	enumeraterd   r'   )rI   r-   irX   rC   r   r   r   rJ   :  s
    
zSortedMap.__init__c             C   s   | j | }| j| d S )Nr   )rk   rH   )rI   rX   rm   r   r   r   __getitem__A  s    
zSortedMap.__getitem__c             C   s
   t | jS )N)lenrH   )rI   r   r   r   __len__E  s    zSortedMap.__len__c             C   s   t dd | jD S )Nc             s   s   | ]\}}|V  qd S )Nr   )r#   rX   rC   r   r   r   rY   I  s    z%SortedMap.__iter__.<locals>.<genexpr>)iterrH   )rI   r   r   r   __iter__H  s    zSortedMap.__iter__N)rf   rg   rh   __doc__rJ   rn   rp   rr   r   r   r   r   rj   6  s
   rj   c                   s   e Zd Z fddZ  ZS )
UniqueDictc                s,   || krt d|f tt| || d S )Nzkey already in dictionary: %r)AssertionErrorrU   rt   __setitem__)rI   keyrM   )rW   r   r   rv   M  s    zUniqueDict.__setitem__)rf   rg   rh   rv   ri   r   r   )rW   r   rt   L  s   rt   c               @   s$   e Zd ZdZdddZdddZdS )	cached_propertya
  
    Decorator that converts a method with a single self argument into a
    property cached on the instance.

    Optional ``name`` argument allows you to make cached properties of other
    methods. (e.g.  url = cached_property(get_absolute_url, name='url') )
    Nc             C   s   || _ |p|j| _d S )N)funcrf   rL   )rI   ry   rL   r   r   r   rJ   ^  s    zcached_property.__init__c             C   s&   |d kr| S |  | }|j| j< |S )N)ry   __dict__rL   )rI   instancer]   resr   r   r   __get__b  s    zcached_property.__get__)N)N)rf   rg   rh   rs   rJ   r}   r   r   r   r   rx   V  s   
rx   c                s"   t   fddd_S )Nc                 s   j s  } | _d_ jS )NT)_ranZ_result)r|   )fninnerr   r   r   j  s
    zrunonce.<locals>.innerF)	functoolswrapsr~   )r   r   )r   r   r   runoncei  s    r   c             C   s@   t | tst| dkr&tt| d S tt|  d d S dS )zL
    Return the number of bits necessary to represent integer `intval`.
    r      r   N)r^   	INT_TYPESru   ro   bin)Zintvalr   r   r   
bit_lengthv  s    r   c             #   s2    fdd}d}xt  }|||V  |}qW dS )a  
    Given a list, return an infinite iterator of iterators.
    Each iterator iterates over the list from the last seen point up to
    the current end-of-list.

    In effect, each iterator will give the newly appended elements from the
    previous iterator instantiation time.
    c                s   t  | | S )N)rq   )startstop)lstr   r   sublist_iterator  s    z%stream_list.<locals>.sublist_iteratorr   N)ro   )r   r   r   r   r   )r   r   stream_list  s    	r   c               @   s   e Zd Zdd Zdd ZdS )BenchmarkResultc             C   s.   || _ || _t|| | _t| j| _d S )N)ry   loopnpZarrayrecordsminbest)rI   ry   r   r   r   r   r   rJ     s    zBenchmarkResult.__init__c             C   s0   t | jd| j}|| j| jjt| jf}d| S )Nrf   z)%20s: %10d loops, best of %d: %s per loop)getattrry   r   r   sizeformat_timer   )rI   rL   argsr   r   r   r\     s    zBenchmarkResult.__repr__N)rf   rg   rh   rJ   r\   r   r   r   r   r     s   r   c             C   sL   d  }d}x.|d d D ]}| |kr(P |d }qW |d }d| | |f S )Nzs ms us ns psr   i  z%.1f%s)split)ZtmZunitsbaseZunitr   r   r   r     s    r   c             C   s   t | }d}|d|}x(t|| dkrB|d9 }|d|}qW t|| }||krdt| ||S |d | }t|| d d}tdtt	| }|d|}t| ||S )Nr   r   
   r   )
timeitZTimerrepeatr   r   maxintmathZceilZlog10)ry   ZmaxsecZtimerZnumberr)   r   Zmax_per_run_timer   r   r   r   	benchmark  s    
r   )newrangec             C   s   | |}|t krt S | S )N)NotImplemented)opr_   	op_resultr   r   r   _not_op  s    r   c             C   s    | |}|t krt S |p||kS )N)r   )r   rI   r_   r   r   r   r   	_op_or_eq  s    r   c             C   s"   | |}|t krt S | o ||kS )N)r   )r   rI   r_   r   r   r   r   _not_op_and_not_eq  s    r   c             C   s"   | |}|t krt S | p ||kS )N)r   )r   rI   r_   r   r   r   r   _not_op_or_eq  s    r   c             C   s    | |}|t krt S |o||kS )N)r   )r   rI   r_   r   r   r   r   _op_and_not_eq  s    r   c             C   s4   t dkr$tt|}t| |}||kS |t| kS dS )zP
    Whether operator *op* on *cls* is inherited from the root object type.
    )r   N)r	   r   objectdir)clsr   Z	object_opZcls_opr   r   r   _is_inherited_from_object  s
    

r   c                s   ddd fddd fddd fgddd fd	d
d fddd fgd	dd fddd fddd fgddd fddd fd	dd fgd} fdd|D }|st dt|}x<|| D ]0\}}||kr||_tt|j|_t || qW  S )z6Class decorator that fills in missing ordering methods__gt__c             S   s   t | j| |S )N)r   __lt__)rI   r_   r   r   r   <lambda>  s   z total_ordering.<locals>.<lambda>__le__c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r     s    __ge__c             S   s   t | j|S )N)r   r   )rI   r_   r   r   r   r     s    c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r     s   r   c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r     s   c             S   s   t | j|S )N)r   r   )rI   r_   r   r   r   r     s    c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r     s   c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r   !  s    c             S   s   t | j|S )N)r   r   )rI   r_   r   r   r   r   "  s    c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r   $  s   c             S   s   t | j| |S )N)r   r   )rI   r_   r   r   r   r   '  s   c             S   s   t | j|S )N)r   r   )rI   r_   r   r   r   r   )  s    )r   r   r   r   c                s   g | ]}t  |s|qS r   )r   )r#   r   )r   r   r   r%   ,  s    z"total_ordering.<locals>.<listcomp>z6must define at least one ordering operation: < > <= >=)
ValueErrorr   rf   r   r   rs   setattr)r   Zconvertrootsrootopnameopfuncr   )r   r   total_ordering  s>    r   c             C   s2   | }d}x$|r,|j rd}P |js$P q
|j}q
W |S )NFT)ZhandlersZ	propagateparent)Zloggercrvr   r   r   logger_hasHandlers9  s    
r   z	<dynamic>)refc               @   s   e Zd ZdZdZi ZdZe Z	dZ
dZG dd dZdd Zdd	d
Zdd Zdd Zedd Zedd Zejdd Zdd Zedd Zedd ZdS )finalizea  Class for finalization of weakrefable objects

    finalize(obj, func, *args, **kwargs) returns a callable finalizer
    object which will be called when obj is garbage collected. The
    first time the finalizer is called it evaluates func(*arg, **kwargs)
    and returns the result. After this the finalizer is dead, and
    calling it just returns None.

    When the program exits any remaining finalizers for which the
    atexit attribute is true will be run in reverse order of creation.
    By default atexit is true.
    r   Fc               @   s   e Zd ZdZdS )zfinalize._Info)weakrefry   r   kwargsatexitindexN)rf   rg   rh   	__slots__r   r   r   r   _Infok  s   r   c             O   sz   | j s*dd l}|| j dt_ |t |  }t|| |_||_	||_
|pPd |_d|_t| j|_|| j| < dt_d S )Nr   T)_registered_with_atexitr   register	_exitfuncr   r@   r   r   r   ry   r   r   next_index_iterr   	_registry_dirty)rI   objry   r   r   r   infor   r   r   rJ   n  s    


zfinalize.__init__Nc             C   s0   | j | d}|r,| js,|j|j|jp(i S dS )zZIf alive then mark as dead and return func(*args, **kwargs);
        otherwise return NoneN)r   pop	_shutdownry   r   r   )rI   rS   r   r   r   r   __call__  s    
zfinalize.__call__c             C   sH   | j | }|o| }|dk	rD| j | drD||j|j|jp@i fS dS )z^If alive then mark as dead and return (obj, func, args, kwargs);
        otherwise return NoneN)r   rA   r   r   ry   r   r   )rI   r   r   r   r   r   detach  s    zfinalize.detachc             C   s:   | j | }|o| }|dk	r6||j|j|jp2i fS dS )zMIf alive then return (obj, func, args, kwargs);
        otherwise return NoneN)r   rA   r   ry   r   r   )rI   r   r   r   r   r   peek  s    zfinalize.peekc             C   s
   | | j kS )zWhether finalizer is alive)r   )rI   r   r   r   alive  s    zfinalize.alivec             C   s   | j | }t|o|jS )z*Whether finalizer should be called at exit)r   rA   boolr   )rI   r   r   r   r   r     s    zfinalize.atexitc             C   s   | j | }|rt||_d S )N)r   rA   r   r   )rI   rM   r   r   r   r   r     s    c             C   s^   | j | }|o| }|d kr6dt| jt| f S dt| jt| t|jt|f S d S )Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)r   rA   r   r]   rf   id)rI   r   r   r   r   r   r\     s    zfinalize.__repr__c             C   s2   dd | j  D }|jdd d dd |D S )Nc             S   s   g | ]\}}|j r||fqS r   )r   )r#   frm   r   r   r   r%     s    z-finalize._select_for_exit.<locals>.<listcomp>c             S   s
   | d j S )Nr   )r   )itemr   r   r   r     s    z+finalize._select_for_exit.<locals>.<lambda>)rw   c             S   s   g | ]\}}|qS r   r   )r#   r   rm   r   r   r   r%     s    )r   r[   sort)r   Lr   r   r   _select_for_exit  s    zfinalize._select_for_exitc             C   s   d}z| j rdd l}| r(d}|  d }xj|d ks<tjrJ|  }dt_|sPP | }y
|  W n" tk
r   t	j
t	   Y nX || j ks.tq.W W d dt_|r|  X d S )NFr   T)r   gc	isenableddisabler   r   r   r   	Exceptionsys
excepthookexc_inforu   r   enable)r   reenable_gcr   pendingr   r   r   r   r     s.    
zfinalize._exitfunc)N)rf   rg   rh   rs   r   r   r   	itertoolscountr   r   r   r   rJ   r   r   r   propertyr   r   setterr\   classmethodr   r   r   r   r   r   r   R  s$   
	r   c               C   s   d S )Nr   r   r   r   r   r     s    r   )r   )Z
__future__r   r   r   r   collectionsr   ior   r   Z	threadingr   r   r   r   typesr   Znumpyr   ZsixZ	cStringIOr   ImportErrorZnumba.configr	   r
   Zcollections.abcr   ZIS_PY3builtinsr   r   Zlongint	get_identinternreplacer   r   r   ZthreadZ__builtin__Zlongplatformr   inspectr   Zpysignaturer    ZpySignaturer!   ZpyParameterZfuncsigsr"   r.   operatoraddsubmulfloordivtruedivmodpowand_or_xorlshiftrshifteqneltlegtgeis_is_notcontainsZBINOPS_TO_OPERATORSiaddisubimul	ifloordivitruedivimodipowiandiorixorilshiftirshiftZINPLACE_BINOPS_TO_OPERATORSposneginvertnot_truthZUNARY_BUITINS_TO_OPERATORSZOPERATORS_TO_BUILTINSversion_infoZHAS_MATMUL_OPERATORZdivZidivmatmulimatmulr?   r@   rB   rD   r   rE   rj   dictrt   rx   r   r   r   r   r   r   rangeZRANGE_ITER_OBJECTSZxrangeZfuture.types.newranger   r   r   r   r   r   r   r   r   Z_dynamic_modnameZ_dynamic_moduleZmoves__builtins__r   r   r   r   ru   r   r   r   r   <module>   st  
	











1


			, 