ó
\K]c           @` sÚ  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l j j Z d  d l j j Z d  d l Z d d l m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ d  d l0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 d d l5 m6 Z6 d  d	 l m7 Z7 d  d
 l8 m9 Z9 d  d l: m; Z; d  d l< m= Z= m> Z> d  d l Z? d  d l@ Z@ d d lA mB ZB d „  ZC eC e jD e jE <d „  ZF d „  ZG d „  ZH d „  ZI d „  ZJ d „  ZK d „  ZL d „  ZM d „  ZN d „  ZO d „  ZP d „  ZQ d „  ZR d „  ZS d „  ZT d „  ZU d „  ZV d  „  ZW d! „  ZX d" „  ZY d# „  ZZ d$ „  Z[ d% „  Z\ d S(&   i    (   t   print_functiont   divisiont   absolute_importN(   t   OrderedDicti   (   t   compilert   irt   typest   sixt   cgutilst   sigutilst   loweringt   parfor(   t   add_offset_to_labelst   replace_var_namest   remove_delst   legalize_namest   mk_unique_vart   rename_labelst   get_name_var_tablet   visit_vars_innert   get_definitiont   guardt   find_callnamet   get_call_tablet   is_puret   get_np_ufunc_typt   get_unused_var_namet   find_potential_aliasest   is_const_call(   t   compute_use_defst   compute_live_mapt   compute_dead_mapst   compute_cfg_from_blocks(   t	   signature(   t   config(   t   ParallelOptions(   t   exec_(   t   print_wrappedt   ensure_parallel_support(   t   NumbaParallelSafetyWarningc   Z      C` sþ  d d l  m } t ƒ  |  j j } |  j } |  j j } t j | ƒ |  j _ |  j j } |  j } t	 j
 r‚ t d ƒ | j ƒ  n  | j j } | j j }	 t	 j
 rÅ t d | j d t | j ƒ ƒ n  x: | j j D], }
 t	 j
 rñ t d |
 ƒ n  |  j |
 ƒ qÒ WxR | j D]G } | | k r| | } t j |	 | | ƒ } |  j | j | ƒ qqWi  } i  } t j j | | j | |  j | | ƒ t	 j
 r®t d | ƒ t d | ƒ n  | j d/ k sÃt ‚ t j j | | j ƒ } t j j  | | j |  j j! ƒ \ } } t" | ƒ } i  } | d	 k rß| ƒ  } | j j }	 | j j } x›t# | ƒ D]Š} |  j j | | } t j |	 | | | ƒ } t$ | ƒ } | j% } t	 j
 rÁt d
 | | | t& j' | ƒ ƒ n  t( | t& j) j* ƒ ræ| j+ d } n d } t j |	 t, d ƒ | ƒ } t- t. j/ ƒ } | j0 | t& j1 t& j2 | ƒ t& j' | ƒ f i  ƒ } | | | j <t j3 t j4 d t. j/ d | ƒ| | ƒ } |  j | ƒ t j |	 t, d ƒ | ƒ }  t j3 t j5 | | ƒ |  | ƒ }! t& j2 | |  j <|  j |! ƒ t j |	 t, d ƒ | ƒ }" t& j1 t& j2 | ƒ | |" j <|  g }# t( | t& j) j* ƒ rAt j |	 t, d ƒ | ƒ }$ t& j1 t& j2 | j+ ƒ | |$ j <t j6 j7 | d | ƒ }% t j3 |% |$ | ƒ }& |  j |& ƒ x t# | j+ ƒ D]{ }' t j |	 t, d ƒ | ƒ }( t j6 j8 |$ |' d/ | ƒ }) t& j2 | |( j <t j3 |) |( | ƒ }* |  j |* ƒ |# |( g 7}# q¿Wn  t j6 j9 |# | ƒ }+ t j3 |+ |" | ƒ }, |  j |, ƒ t j6 j: | |" g i  d | ƒ}- t j |	 t, d ƒ | ƒ }. | | |. j <t j3 |- |. | ƒ }/ | |  j j! |- <|  j |/ ƒ |. | | j <| | | d	 }0 |0 d/ k r
t( | t& j) j* ƒ r±t j |	 t, d ƒ | ƒ }1 t- t. j; ƒ }2 | j0 |2 t& j1 t& j2 | j+ ƒ | t& j' | ƒ f i  ƒ }3 |2 | |1 j <t j3 t j4 d t. j; d | ƒ|1 | ƒ }4 |  j |4 ƒ t j |	 t, d ƒ | ƒ }5 t j3 t j5 |0 | ƒ |5 | ƒ }6 | | |5 j <|  j |6 ƒ t j6 j: |1 |$ |5 g i  d | ƒ}7 |3 |  j j! |7 <t j |	 t, d ƒ | ƒ }8 t j3 |7 |8 | ƒ }9 | | |8 j <|  j |9 ƒ qt j |	 t, d ƒ | ƒ }8 t j3 t j5 |0 | ƒ |8 | ƒ }9 | | |8 j <|  j |9 ƒ n | }8 xÅ t# | ƒ  ƒ D]´ }' t j |	 t, d ƒ | ƒ }: t j3 t j5 |' | ƒ |: | ƒ }; t& j< | |: j <|  j |; ƒ t j= |. |: |8 | ƒ }< t> t& j? | |. j | |: j | ƒ |  j j! |< <|  j |< ƒ q WqNWn  t j | j@ ƒ }= |= jA d d ƒ | | jB d	 jC j }> x1 | jB d D]" }? | |? jC j |> k s&	t ‚ q&	WtD t j _E tF |  | | | | |= i  tG | ƒ |> | j ƒ
 \ }@ }A }B }C }D tH t j _E d g |A }A t" | ƒ }E t" |A ƒ t" | ƒ |E }F t	 j
 r#
t d |A ƒ t d |F ƒ t d | ƒ t d | ƒ t d  |E ƒ n  tI | jJ |F |E |A |C |B | j | ƒ }G t	 j
 rc
t d! |G ƒ n  g  | jB D] }? |? jK |? jL |? jM f ^ qm
}H t	 j
 rº
t d" | jB ƒ t d# |H ƒ n  tN |  |@ |G |B |A |D |H | | | | j |> | j ƒ t	 j
 rtO jP jQ ƒ  n  | d	 k rî| ƒ  } | j j }	 | j j } x~t# | ƒ D]p} | | }I | |I }J |  j j |I } t	 jR r\d$ }K t& jS |K ƒ }L t j |	 t, d% ƒ | ƒ }M t j3 d& t j5 d& |K d | ƒ d' |M d | ƒ }N |L | |M j <|  j |N ƒ t jT d( |M |J g d) d/ d | ƒ }O t> t& j? | |M j | |J j ƒ |  j j! |O <t d$ |O ƒ |  j |O ƒ n  xRt# | ƒ  ƒ D]A}' t j |	 t, d ƒ | ƒ }: t j3 t j5 |' | ƒ |: | ƒ }; t& j< | |: j <|  j |; ƒ t j |	 t, d* ƒ | ƒ }P t j6 jU |J |: | ƒ }Q | | |P j <t> | | |J j | |: j ƒ |  j j! |Q <t j3 |Q |P | ƒ }R |  j |R ƒ t j |	 |I d+ | ƒ }S t j3 |P |S | ƒ }T |I d+ | k r¥| | |S j <n  |  j |T ƒ t	 jR r½d, }K t& jS |K ƒ }L t j |	 t, d% ƒ | ƒ }M t j3 d& t j5 d& |K d | ƒ d' |M d | ƒ }N |L | |M j <|  j |N ƒ t jT d( |M |: |P |S g d) d/ d | ƒ }O t> t& j? | |M j | |: j | |P j | |S j ƒ |  j j! |O <t d$ |O ƒ |  j |O ƒ n  xí | |I d D]Ý }U t( |U t j3 ƒ rœ|U jV }V t( |V t j6 ƒ rœ|V jW d- k rœ|V jX j |S j k rœ|  j j! |V }W t" |W jY ƒ d. k sNt ‚ |W jY d	 | f }X |W jZ d( |X ƒ }W |  j j! j[ |V ƒ |W |  j j! |V <qœn  |  j |U ƒ qÌWqlWqAWx6 | j\ ƒ  D]% }Y |  j t j] |Y j d | ƒƒ qÂWn  | |  j _ d/ S(0   s  Lowerer that handles LLVM code generation for parfor.
    This function lowers a parfor IR node to LLVM.
    The general approach is as follows:
    1) The code from the parfor's init block is lowered normally
       in the context of the current function.
    2) The body of the parfor is transformed into a gufunc function.
    3) Code is inserted into the main function that calls do_scheduling
       to divide the iteration space for each thread, allocates
       reduction arrays, calls the gufunc function, and then invokes
       the reduction function across the reduction arrays to produce
       the final reduction values.
    i   (   t   get_thread_countt   _lower_parfor_parallels   init_block = t    s   lower init_block instr = t	   alias_mapt   arg_aliasesi    t
   redvar_typt
   empty_funct   emptyt   loct   num_threadst   tuple_size_vart   redarr_shapet   shapet   redshapeonedimt   redarrt	   full_funct   fullt   init_valt   redtosett	   index_vart   error_modelt   numpyt   scheds   func_args = s   num_inputs = s   parfor_outputs = s   parfor_redvars = s   num_reductions = s   gu_signature = s   loop_nests = s   loop_ranges = t	   res_printt	   str_constt   valuet   targett   argst   varargt   redelems   #initt   one_res_printt   inplace_binopi   N(^   t   parallelR(   R&   t   contextt   typing_contextt   fndesct   typemapt   copyt   varmapR"   t   DEBUG_ARRAY_OPTt   printt   dumpt
   init_blockR0   t   scopet   typet   bodyt
   lower_instt   racesR   t   Vart   _alloca_vart   namet   numbaR   t   find_potential_aliases_parfort   paramst   func_irt   Nonet   AssertionErrort   get_parfor_outputst   get_parfor_reductionst	   calltypest   lent   ranget   redtyp_to_redarraytypet   dtypeR   t   DTypet
   isinstancet   npytypest   Arrayt   ndimR   R   t   npR/   t   resolve_function_typet   UniTuplet   intpt   Assignt   Globalt   Constt   Exprt   getattrt   static_getitemt   build_tuplet   callR8   t   uintpt   SetItemR!   t   nonet   flagst   sett
   loop_nestst   index_variablet   Truet   sequential_parfor_loweringt   _create_gufunc_for_parfor_bodyt   boolt   Falset   _create_shape_signaturet   get_shape_classest   startt   stopt   stept   call_parallel_gufunct   syst   stdoutt   flusht   DEBUG_ARRAY_OPT_RUNTIMEt   StringLiteralt   Printt   getitemRA   t   opt   rhsRC   t   replacet   popt   valuest   Del(Z   t   lowererR   R(   t	   typingctxt	   targetctxt   orig_typemapRL   RN   R0   RS   t   instrt   racevart   rvtypt   rvR+   R,   t   parfor_output_arrayst   parfor_redvarst   parfor_reddictt   nredvarst   redarrst   thread_countt   iR-   t   redvart   redarrvar_typt   reddtypet	   redarrdimR.   t   ff_fntyt   ff_sigt   empty_assignt   num_threads_vart   num_threads_assignt   size_vart   size_var_listt   redshape_vart   redshape_getattrt   redshape_assignt   jt	   onedimvart   onedimgetitemt   onedimassignt	   size_callt   size_assignt
   empty_callt
   redarr_vart   empty_call_assignR9   R7   t	   full_fntyt   full_sigt   full_assignt   init_val_vart   init_val_assignt	   full_callR:   t   redtoset_assignR;   t   index_var_assignt
   redsetitemR|   t   index_var_typt   lt   funct	   func_argst   func_sigt   redargstartdimt   func_arg_typest   num_reductionst
   num_inputst   gu_signaturet   loop_rangesRZ   R6   t   res_print_strt   strconsttypt   lhst
   assign_lhsR?   t   oneelemt   oneelemgetitemt   oneelemassignt   init_vart   init_assignt   instR“   t   ctt   ctargst   v(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR)   $   sì   			
	"	
						"	*!	!	*!$!!	' '			.	
		

	!$	
!$	!	


	6&c      	   ` sg  t  j r\ t d | | | | ƒ x: | d D]+ } t d | t | ƒ |  | d | ƒƒ q* Wn  t | ƒ | }	 g  | d D]* }
 |
 | k r› |  |
 d | ƒn d ^ qw } t ƒ  } x5 | D]- } | r· x | D] } | j | ƒ qÊ Wq· q· W| rþ t | ƒ d n d } | j d | f ƒ | j | ƒ i  ‰ t	 d ƒ } x7 | D]/ } | d k r=t
 | ƒ ˆ | <| d 7} q=q=Wi | d 6‰  ‡  f d	 †  ‰ g  } g  } d } d } t  j rÊt d
 | ƒ t d | ƒ n  x t | | ƒ D] \ } } | d } | rt ‡ ‡ f d †  | Dƒ ƒ } n d } | |	 k rB| j | | | ƒ qÚ| j | ƒ | | 7} qÚW| | f S(   s&   Create shape signature for GUFunc
    R…   i   t   argumentRL   iÿÿÿÿi    t   at   latest_alphac         ` s6   |  d k r | |  Sˆ  d c d 7<t  ˆ  d ƒ Sd  S(   Ni    Rá   i   (   t   chr(   t   ct	   class_map(   t
   alpha_dict(    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt
   bump_alpha°  s    RC   t   classesc         3` s   |  ] } ˆ  | ˆ ƒ Vq d  S(   N(    (   t   .0Rã   (   Ræ   Rä   (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pys	   <genexpr>Á  s    (   iÿÿÿÿ(    (    (   R"   RO   RP   RT   Rd   R}   t   addt   maxt   insertt   ordRâ   t   zipt   tuplet   append(   R†   RÏ   RÎ   RC   RÌ   RË   RW   RL   R¦   t
   num_inoutst   varRç   t	   class_sett   _classt	   max_classt   alphabett   nt   gu_sint   gu_soutt   countt   syms_sint   clst   argt   dim_syms(    (   Rå   Ræ   Rä   s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR…   ‹  sN    	,;		
"c         C` s7   x0 t  |  j ƒ D] \ } } t d | d | ƒ q Wd  S(   Ns       R*   (   t	   enumerateRU   RP   (   t   blockR¦   RÛ   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   _print_blockÍ  s    c         C` s8   x1 |  j  ƒ  D]# \ } } t d | ƒ t | ƒ q Wd S(   s%   Pretty-print a set of IR blocks.
    s   label: N(   t   itemsRP   R   (   t	   body_dictt   labelRÿ   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   _print_bodyÑ  s    c         C` sa   |  j  ƒ  } t | j ƒ  ƒ } t | j ƒ  ƒ } | | j } | | j j t j | | ƒ ƒ | S(   N(	   RM   t   mint   keysRê   R0   RU   Rï   R   t   Jump(   t	   loop_bodyt   blockst   first_labelt
   last_labelR0   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   wrap_loop_bodyÙ  s     c         C` s.   t  |  j ƒ  ƒ } |  | j d  |  | _ d  S(   Niÿÿÿÿ(   Rê   R  RU   (   R  R  (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   unwrap_loop_bodyá  s    c         C` sI   |  | k r n6 |  | k r8 | j  |  ƒ | j |  ƒ n | j  |  ƒ d S(   s_  If the variable is already defined more than once, do nothing.
       Else if defined exactly once previously then transition this
       variable to the defined more than once set (remove it from
       def_once set and add to def_more set).
       Else this must be the first time we've seen this variable defined
       so add to def_once set.
    N(   Ré   t   remove(   t   a_deft   def_oncet   def_more(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   add_to_def_once_setså  s    c         C` sô  |  j  t j ƒ } xÛ| D]Ó} | j j } t | | | ƒ | j }	 t |	 t j ƒ r t |	 j t	 j
 ƒ r |	 j j | | <q n  t |	 t j ƒ rÐ |	 j d k rÐ |	 j j | k rÐ |	 j j |	 j f | | <n  t |	 t j ƒ rg|	 j d k rg|	 j j | k rg| |	 j j \ }
 } |
 | k rT| |
 } t | | ƒ sdt |
 | | ƒ qdqgt |
 | | ƒ n  t |	 t j ƒ r |	 j d k r xa |	 j D]S } t | t j ƒ r¶| j } n  | | } t | d t ƒ r’t | | | ƒ q’q’Wq q Wd S(   sË  Effect changes to the set of variables defined once or more than once
       for a single block.
       block - the block to process
       def_once - set of variable names known to be defined exactly once
       def_more - set of variable names known to be defined more than once
       getattr_taken - dict mapping variable name to tuple of object and attribute taken
       module_assigns - dict mapping variable name to the Global that they came from
    Ru   Rx   t   mutableN(   t
   find_instsR   Rq   RB   RZ   R  RA   Ri   Rr   t   pytypest
   ModuleTypet   __name__Rt   R’   t   attrRÉ   R   RC   RX   Ru   R„   (   Rÿ   R  R  t   getattr_takenRL   t   module_assignst   assignmentst
   one_assignR  R“   t   base_objt	   base_attrt   base_mod_namet   argvart   avtype(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   compute_def_once_blockõ  s0    
	33
!
c   	   	   C` s›   x” |  j  ƒ  D]† \ } } t | | | | | | ƒ x^ | j D]S } t | t j ƒ r< t | j | | | | | ƒ t | j | | | | | ƒ q< q< Wq Wd S(   sÞ   Compute the set of variables defined exactly once in the given set of blocks
       and use the given sets for storing which variables are defined once, more than
       once and which have had a getattr call on them.
    N(	   R  R"  RU   Ri   R   t   ParforRR   t   compute_def_once_internalR  (	   R  R  R  R  RL   R  R  Rÿ   RÛ   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR$  3  s    c         C` s;   t  ƒ  } t  ƒ  } i  } i  } t |  | | | | | ƒ | S(   sR   Compute the set of variables defined exactly once in the given set of blocks.
    (   R}   R$  (   R  RL   R  R  R  R  (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   compute_def_onceE  s    		c         C` s,   t  |  t j ƒ s t ‚ | j |  j ƒ |  S(   N(   Ri   R   RX   R`   Ré   RZ   (   Rñ   t   varset(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt	   find_varsO  s    c         C` s:  t  ƒ  } t |  j t | ƒ | j | ƒ } t | ƒ d k r· t |  j d  | ƒ r· t j	 d k rq t
 d |  ƒ n  | j |  ƒ t | |  j j t j j ƒ s³ | |  j j g 7} n  t St | ƒ d k r| j |  d f ƒ t j	 d k r6t
 d |  d ƒ q6n5 | j |  d f ƒ t j	 d k r6t
 d |  d ƒ n  t S(	   Ni    i   s   Will hoist instructiont
   dependencyt   Instructions.    could not be hoisted because of a dependency.s   not pures,    could not be hoisted because it isn't pure.(   R}   R   RA   R'  t
   differenceRd   R   R_   R"   RO   RP   Rï   Ri   RB   RZ   R   Rj   Rk   R€   R„   (   RÛ   t   dep_on_paramt
   call_tablet   hoistedt   not_hoistedRL   t   usest   diff(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   _hoist_internalT  s$    	'c         C` s‡   x€ | j  D]u } t | t j ƒ s4 t | t j ƒ rJ |  j | j j ƒ q
 t | t j	 ƒ r
 t
 |  | j ƒ t |  | j ƒ q
 q
 Wd  S(   N(   RU   Ri   R   t   StaticSetItemRz   Ré   RB   RZ   R   R#  t   find_setitems_blockRR   t   find_setitems_bodyR  (   t   setitemsRÿ   RÛ   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR3  k  s    $c         C` s.   x' | j  ƒ  D] \ } } t |  | ƒ q Wd  S(   N(   R  R3  (   R5  R  R  Rÿ   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR4  s  s    c      
   C` sÅ  t  j  |  ƒ } g  } g  } t | | ƒ } t | ƒ \ } }	 t ƒ  }
 t |
 | ƒ t t | ƒ j |
 ƒ ƒ } xK| j ƒ  D]=\ } } g  } x| j D]} t	 | t
 j ƒ rä | j j | k rä t | | | | | | ƒ rq– qn¹ t	 | t j ƒ rg  } t j d k r"t d ƒ | j ƒ  n  xi | j j D][ } t	 | t
 j ƒ r}| j j | k r}t | | | | | | ƒ r}q/q}n  | j | ƒ q/W| | j _ n  | j | ƒ q– W| | _ qz W| | f S(   Ni   R   (   RM   R%  R   R}   R4  t   listR*  R  RU   Ri   R   Rq   RB   RZ   R1  R   R#  R"   RO   RP   RQ   RR   Rï   (   t   parfor_paramsR  RL   t   wrapped_blocksR+  R-  R.  R  R,  t   reverse_call_tableR5  R  Rÿ   t	   new_blockRÛ   t   new_init_blockt   ib_inst(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   hoistw  s>    	$	
	c         C` s   t  |  t j j ƒ S(   N(   Ri   R   Rj   Rk   (   t   redtype(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   redtyp_is_scalar   s    c         C` sJ   d } t  |  t j j ƒ r4 | |  j 7} |  j }  n  t j j |  | d ƒ S(   si   Go from a reducation variable type to a reduction array type used to hold
       per-worker results.
    i   t   C(   Ri   R   Rj   Rk   Rl   Rg   (   t   redtypRª   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyRf   £  s
    c         C` sG   t  |  t j j ƒ s t ‚ t j j |  j t d |  j d ƒ |  j ƒ S(   sÖ   Given a reduction array type, find the type of the reduction argument to the gufunc.
       Scalar and 1D array reduction both end up with 1D gufunc param type since scalars have to
       be passed as arrays.
    i   (	   Ri   R   Rj   Rk   R`   Rg   Rê   Rl   t   layout(   t   redarraytyp(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   redarraytype_to_sig¯  s    c         C` sJ   t  |  ƒ } x7 | j ƒ  D]) \ } } | | k r | | | | <q q W| S(   sQ   We use ir_utils.legalize_names to replace internal IR variable names
        containing illegal characters (e.g. period) with a legal character
        (underscore) so as to create legal variable names.
        The original variable names are in the typemap so we also
        need to add the legalized name to the typemap as well.
    (   R   R  (   t   namesRL   t   outdictt   xt   y(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   legalize_names_with_typemap·  s
    c
   R   	   C` sä  | j  j }
 t j | j ƒ } t | ƒ t | j ƒ } g  | j D] } | j j ^ qA } | j	 } t
 j j | | ƒ } |  j j } t
 j j | | |  j j ƒ \ } } t t t | ƒ t | ƒ t | ƒ ƒ ƒ } |	 j t | ƒ ƒ }	 x. |	 D]& } d | } t j t | |
 ƒ ƒ qï Wt |	 | | |  j j ƒ t j d k r¨t d | d t | ƒ ƒ t d | d t | ƒ ƒ t d | d t | ƒ ƒ t d | d t | ƒ ƒ n  g  } g  } x} | D]u } | d } | j | ƒ t | | ƒ } | j | ƒ t | ƒ } | | k r&| | | k s0t  ‚ q»| | | <q»W| | | } t j d k r©t d | d t | ƒ ƒ t d	 | d t | ƒ ƒ t d
 | d t | ƒ ƒ t! | ƒ n  t" | | | ƒ } t j d k rót d t | j# ƒ  ƒ d t | ƒ ƒ n  t" | | ƒ } g  | D] } | | ^ q	} t j d k r®t d t | j# ƒ  ƒ d t | ƒ ƒ t d | d t | ƒ ƒ x? | D]4 }  t d |  ƒ t d | |  d t | |  ƒ ƒ qsWn  g  | D] } | | ^ qµ}! g  | | D] } | | ^ qÖ| }" t$ | | ƒ | }# g  | D] } | | ^ q
} | }$ g  } t% }% xt t& t |$ ƒ ƒ D]` }& |% r”|& t | ƒ k  r”t' |! |& t( j) j* ƒ r”| j |$ |& d ƒ qE| j |$ |& ƒ qEWt$ | | ƒ t+ | ƒ }' t, d |' ƒ }( t j d k rüt d | d t | ƒ ƒ n  d t- t. | ƒ ƒ j/ d d ƒ }) t j rCt d t |) ƒ d |) ƒ n  d }* |* d |) d d j0 | ƒ d 7}* x^ t& t | ƒ ƒ D]J }& |% rt' |! |& t( j) j* ƒ r|* d |$ |& d | |& d 7}* qqWxt t1 | | ƒ D]c \ } } t2 | | ƒ r|* d | | d | | d  7}* qÝ|* d | | d! | | d 7}* qÝWxu t& | ƒ D]g }+ x" t& |+ d ƒ D] }, |* d 7}* qhW|+ }- |* d" | |+ d# t3 |- ƒ d$ t3 |- | ƒ d% 7}* qQWt j4 r:x" t& | d ƒ D] }, |* d 7}* qÖW|* d& 7}* x6 t& | ƒ D]( }+ |* d' | |+ d( | |+ d) 7}* qW|* d 7}* n  x" t& | d ƒ D] }, |* d 7}* qKW|* |( d* 7}* i  }. xˆ t1 | | ƒ D]w \ } } t2 | | ƒ rÎ|* d | | d+ | | d, 7}* d |. | <qƒ|* d | | d- | | d. 7}* d/ |. | <qƒW|* d0 7}* t j r-t d1 t |* ƒ d, |* ƒ n  i t5 d2 6}/ i  }0 t6 |* |/ |0 ƒ |0 |) }1 t j rt d3 t |1 ƒ d, |1 ƒ n  t7 j8 |1 ƒ }2 t j rÔt d4 t |2 ƒ ƒ |2 j9 ƒ  t d5 t | ƒ ƒ t! | ƒ n  t+ |2 j: ƒ }3 i  }4 |( g t | j; ƒ  ƒ | }5 x9 |3 j# ƒ  D]+ \ }6 } |6 |5 k r	t< |6 ƒ |4 |6 <q	q	Wt$ |2 j: |4 ƒ t j rr	t d6 ƒ |2 j9 ƒ  n  t
 j( j) j* | d d7 ƒ g |! }7 t j r¹	t d8 t |7 ƒ d, |7 ƒ n  t= |2 j: j> ƒ  ƒ d }8 t? | |8 ƒ } t= | j> ƒ  ƒ d }9 t j4 r x| j# ƒ  D]Œ\ }: }; |; j ƒ  }< |< j@ ƒ  |; j }
 |; jA }= xK|; jB D]@}> |< j |> ƒ t' |> tC jD ƒ rK
| |> jE j t( jF k r
qK
n  d9 jG |> jE j ƒ }? t( jH |? ƒ }@ tC jI |= t< d: ƒ |
 ƒ }A tC jD d; tC jJ d; |? d< |
 ƒ d= |A d< |
 ƒ }B |@ | |A j <|< j |B ƒ tC jK d> |A |> jE g d? dL d< |
 ƒ }C |< j |C ƒ t
 jM jN t( jO | |A j | |> jE j ƒ }D |D |  j j |C <qK
qK
W|< | |: <q
Wn  t j rÀt d@ ƒ t! | ƒ n  tP | ƒ }E tQ | | | |E ƒ \ }F }G |2 j: tR |2 j: j> ƒ  ƒ }H |H jB dA  |F |H jB dA g |H _B tS | ƒ |  jT dB }I i |F dC 6|G dD 6|I jU | jV <t j rzt dE ƒ t! | ƒ n  xR|2 j: j# ƒ  D]A\ }: }; x1tW |; jB ƒ D]\ }J }> t' |> tC jD ƒ r¦|> jE j |( k r¦|> j }
 |; jA }= tC jX |= |
 ƒ }K |; jB |J  |K _B |; jB |J d |; _B tR | j> ƒ  ƒ }L |K j tC jY |L |
 ƒ ƒ x' | j# ƒ  D] \ } }M |M |2 j: | <qVWt= | j> ƒ  ƒ }N |; |2 j: |9 <|K |2 j: |: <|2 j: |N j tC jY |9 |
 ƒ ƒ Pq¦q¦WqŠPqŠWt j rït dF ƒ |2 j9 ƒ  n  tZ |2 j: ƒ |2 _: t |2 j: ƒ t j rHt dG ƒ |2 j9 ƒ  t dH | ƒ t dI | ƒ n  | j[ }O | syt j rmt dJ ƒ n  t\ | _[ n  t7 j] | | |2 |7 t( jO | | ƒ }P |O | _[ tN t( jO |7 Œ }Q t j rÑt dK |Q ƒ n  |P |# |Q |. |" f S(M   s~  
    Takes a parfor and creates a gufunc function for its body.
    There are two parts to this function.
    1) Code to iterate across the iteration space as defined by the schedule.
    2) The parfor body that does the work for a single point in the iteration space.
    Part 1 is created as Python text for simplicity with a sentinel assignment to mark the point
    in the IR where the parfor body should be added.
    This Python text is 'exec'ed into existence and its IR retrieved with run_frontend.
    The IR is scanned for the sentinel assignment where that basic block is split and the IR
    for the parfor body inserted.
    s‘   Variable %s used in parallel loop may be written to simultaneously by multiple workers and may result in non-deterministic or unintended results.i   s   parfor_params = R*   s   parfor_outputs = s   parfor_inputs = s   parfor_redvars = t   _arrs   loop_indices = s   loop_body = s   param_dict = s   ind_dict = s   legal_loop_indices = s   pd = s
   pd type = t   paramt   __sentinel__s   legal parfor_params = s   __numba_parfor_gufunc_%st   -t   _s   gufunc_name t    s   def s   (sched, s   , s   ):
s       s    = np.ascontiguousarray(s   )
t   =s   [0]
s	   =np.copy(s   for s    in range(sched[s	   ], sched[s   ] + np.uint8(1)):
s   print(s   "s   ",t   ,s    = 0
s   [0] = s   
s   [:] = s   [:]
i    s       return None
s   gufunc_txt = Rm   s   gufunc_func = s   gufunc_ir dump s   loop_body dump s   gufunc_ir dump after renaming R@  s   gufunc_param_types = s   {} =R@   RA   R0   RB   RC   RD   s   parfor loop bodyiÿÿÿÿt   parfor_diagnosticsR-  R.  s   After hoistings#   gufunc_ir last dump before renamings   gufunc_ir last dumpR|   RL   s(   No aliases found so adding noalias flag.s   kernel_sig = N(^   RR   R0   RM   R  R   Rd   R~   R   RZ   R]   R[   R   Ra   RK   RL   Rb   Rc   t   sortedR6  R}   R*  t   warningst   warnR'   t   replace_var_with_arrayR"   RO   RP   RT   Rï   Rf   RD  R`   R  RI  R  R   R„   Re   Ri   R   Rj   Rk   R   R   t   hext   hashR”   t   joinRí   R?  t   strRŽ   Rm   R$   R   t   run_frontendRQ   R	  R–   R   Rê   R  R   t   clearRS   RU   R   Rq   RB   t   number_domaint   formatR   RX   Rs   R   R_   t   typingR!   R{   R  R=  R  R  t   metadatat
   hoist_infot   idRþ   t   BlockR  R   t   noaliasR€   t
   compile_ir(R   R˜   R   RL   R™   Rš   R|   t   localst   has_aliasesRÇ   RW   R0   R  t
   parfor_dimRÈ   t   loop_indicesR7  t   parfor_outputsR¡   R¢   t   parfor_inputst   racet   msgt   parfor_redarrst   parfor_red_arg_typesRñ   t   arrt   redarraytypet	   redarrsigt
   param_dictt   ind_dictRÞ   t   legal_loop_indicest   pdt   param_typesRÍ   t   parfor_argst   parfor_params_origt   ascontigt   pindext   loop_body_var_tablet   sentinel_namet   gufunc_namet
   gufunc_txtt   eachdimt   indentt	   sched_dimRÌ   t   globlst   loclst   gufunc_funct	   gufunc_irt	   var_tablet   new_var_dictt   reserved_namesRZ   t   gufunc_param_typest   gufunc_stub_last_labelt	   new_labelR  Rÿ   R:  RS   RÛ   t   strvalRÓ   RÔ   RÕ   t
   print_nodet   sigR8  R-  R.  t   start_blockt   diagnosticsR¦   t
   prev_blockt   body_first_labelt   bt   body_last_labelt	   old_aliast   kernel_funct
   kernel_sig(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR‚   Ç  sú   
"		
%(%	 &"#+	
&
	
		
	
		
	
		!'
	
"

	
			
	

					c   
      C` s~  g  } xq| j  D]f} t | t j ƒ r!| j j |  k r!t j d | j ƒ } t j | j j	 t
 d ƒ | j ƒ } t j | | j <t j | | | j ƒ } | j | ƒ t j | j | | j | j ƒ }	 t t j t j j | | j j d d ƒ t j | | j j ƒ | |	 <| j |	 ƒ q nH t | t j ƒ rit |  i | j d 6| | ƒ t |  | j | | ƒ n  | j | ƒ q W| S(   Ni    s   $const_ind_0i   R@  (   RU   Ri   R   Rq   RB   RZ   Rs   R0   RX   RS   R   R   Ry   Rï   Rz   RA   R!   R{   Rj   Rk   Rp   R   R#  t   replace_var_with_array_internalRR   R  (
   t   varsRÿ   RL   Rc   R:  RÛ   t
   const_nodet	   const_vart   const_assignt   setitem_node(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   replace_var_with_array_in_blockY  s$    $$!Bc         C` s9   x2 | j  ƒ  D]$ \ } } t |  | | | ƒ | _ q Wd  S(   N(   R  RŸ  RU   (   Rš  R  RL   Rc   R  Rÿ   (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyR™  o  s    c         C` s^   t  |  | | | ƒ xD |  D]< } | | } | j | d  ƒ t j j | d d ƒ | | <q Wd  S(   Ni   R@  (   R™  R•   R_   R   Rj   Rk   (   Rš  R  RL   Rc   RÞ   t   el_typ(    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyRV  s  s
    
c   [      ` s¬  ˆ j  ‰  ˆ j } d d l m } m } m } t j r§ t d ƒ t d | ƒ t d | j	 | j
 | j | j ƒ t d | ƒ t d | ƒ t d | ƒ t d	 | ƒ n  t j | ƒ \ } } | j j | j j ƒ } | \ } } | ƒ  | | | | | d
 t d t ƒ} | j } | j j ƒ  t j r:t d | | ƒ n  ‡  ‡ f d †  } t | ƒ } xº t | ƒ D]¬ } | | \ } } } | | ƒ } | | ƒ } | d k s¨t ‚ | | ƒ } | | | f | | <t j ret d j | ƒ | | | ƒ t j | d j | ƒ | | | ƒ qeqeWt j j d ƒ } t j j  | ƒ } t j j  | ƒ }  ˆ  j! t" j# ƒ }! ˆ  j! t" j$ ƒ }" t j j  |! ƒ }# t j j  |" ƒ }$ ˆ  j% t" j$ d ƒ }% ˆ  j% t" j$ d ƒ }& |& j& }' ˆ  j' |! ƒ }( | j( d ƒ | j( d ƒ }) t j rt d | j) ƒ n  | j) r%|! }* |# }+ n |" }* |$ }+ t j* | |* d ˆ  j% t" j$ | ƒ d d ƒ}, t j* | |* d ˆ  j% t" j$ | ƒ d d ƒ}- xt | ƒ D]ó } | | \ } } } | j& |' k rÕ| j+ | |' ƒ } n  | j& |' k rù| j+ | |' ƒ } n  | j& |' k r| j+ | |' ƒ } n  | j, | |& ƒ } | j- | | j. |, ˆ  j% t" j$ | ƒ g ƒ ƒ | j- | | j. |- ˆ  j% t" j$ | ƒ g ƒ ƒ q˜W| ƒ  | d }. t j* | |* d ˆ  j% t" j$ |. ƒ d d ƒ}/ t j rÜd n d }0 t j j/ |# |" |+ |+ |" |+ |! g ƒ }1 | j) r-| j0 j1 |1 d d ƒ}2 n | j0 j1 |1 d d ƒ}2 | j2 |2 ˆ  j% t" j$ | ƒ |, |- ˆ  j% t" j$ | ƒ  ƒ |/ ˆ  j% t" j# |0 ƒ g ƒ g  | D] }3 ˆ j3 |	 |3 j ƒ ^ qž}4 t | ƒ }5 t | ƒ |5 }6 t j r‘x© t | ƒ  ƒ D]• } t j | d t4 | ƒ d ƒ x^ t | d ƒ D]L }7 t j | d | j5 | j. |/ ˆ  j% t" j# | | d |7 ƒ g ƒ ƒ ƒ q*Wt j | d ƒ qõWn  g  | |6  D] }3 ˆ j3 |3 ƒ ^ qœ|4 }8 t |8 ƒ }9 t | ƒ d }: t j* | | d ˆ  j% t" j# d |9 ƒ d d ƒ} g  }; | j- | j6 |/ | ƒ | ƒ |; j7 ˆ  j% t" j# |( ƒ ƒ i  }< i  }= x't |9 ƒ D]} |8 | }> | | }? | | }@ | j. | ˆ  j% t" j# | d ƒ g ƒ }A | |6 k riˆ  j8 |@ ƒ ˆ  | |> ƒ }B t j9 | |B j: |@ j; ƒ }C t j9 | |B j< |@ j; ƒ }D x. t d t |C ƒ ƒ D] }7 |; j7 |C |7 ƒ qW|D d |< | <| j- | j6 |B j= | ƒ |A ƒ q_t> |@ t" j? ƒ r¹	|? | k r3	|@ j@ t" jA k r«ˆ  jB |@ j@ ƒ n t j j d ƒ }E t j* | |E ƒ }F | j- |> |F ƒ | j- | j6 |F | ƒ |A ƒ |> |F f |= |? <|; j7 ˆ  j% t" j# ˆ  j' |E ƒ ƒ ƒ qx
ˆ  j8 |@ ƒ ˆ  | |> ƒ }B t j9 | |B j: |@ j; ƒ }C x+ t t |C ƒ ƒ D] }7 |; j7 |C |7 ƒ q|	W| j- | j6 |B j= | ƒ |A ƒ q_| |: k  r
|@ t" jA k rã	ˆ  jB |@ ƒ n t j j d ƒ }E t j* | |E ƒ }G | j- |> |G ƒ nB |@ t" jA k r8
ˆ  jB |@ ƒ n t j j d ƒ }E t j* | |E ƒ }G | j- | j6 |G | ƒ |A ƒ q_Wi  }H g  }I |) d g }I ˆ  j% t" j# d | ƒ |H |) d <t | ƒ t |8 ƒ k sÔ
t ‚ t | ƒ t | ƒ k sò
t ‚ t | ƒ t | | ƒ k st ‚ t | ƒ t | j	 d ƒ k s9t ‚ x…tC | |8 | | | ƒ D]j\ }? }> }@ }J t> |@ t" jD jE ƒ r|@ j; t |J ƒ } n d } t j rÁt d |? d  |J d! |@ d" | ƒ n  xù |J D]ñ }K t j rít d# |? d$ |@ ƒ n  |? | k rˆ  j% t" j# d ƒ |H |K <nD ˆ  j8 |@ ƒ ˆ  | |> ƒ }B t j9 | |B j< |@ j; ƒ }L |L | |H |K <|K |I k r¯t j rŸt d% |K d& | ƒ t j | |K d' |H |K ƒ n  |I j7 |K ƒ n  | d } qÈWqSWt |H ƒ d }M t j* | |! d |M d d( ƒ}L | j- ˆ  j% t" j# | ƒ  ƒ |L ƒ d } xq |I D]i }K t j rKt j | |K d' |H |K ƒ n  | j- |H |K | j. |L ˆ  j% t" j# | ƒ g ƒ ƒ | d } qW|9 d t |; ƒ }N t j* | |! d ˆ  j% t" j# |N ƒ d d) ƒ}O | j- ˆ  j% t" j# d | |( ƒ |O ƒ xt |9 ƒ D]} | |6 k rÉ| |6 }7 ˆ j jF | |7 }P d, }Q t> |P t" jD jE ƒ ra|P j@ }P |< | }Q n  ˆ  j! |P ƒ }E ˆ  j' |E ƒ }R ˆ  j% t" j# |R ƒ }S |Q d, k	 rÏx# |Q D] }T | jH |S |T ƒ }S q§WqÏn |% }S | j. |O ˆ  j% t" j# d | ƒ g ƒ }A | j- |S |A ƒ q WxZ t t |; ƒ ƒ D]F }7 | j. |O ˆ  j% t" j# d |9 |7 ƒ g ƒ }A | j- |; |7 |A ƒ qWt jI | ƒ }U t j j/ t j jJ ƒ  |  |# |# | g ƒ }V | j0 j1 |V d | ƒ}W ˆ  jK jL | j ƒ t j rët j | d* |W ƒ n  | j2 |W | |L |O |U g ƒ t j r&t j | d+ |W ƒ n  xl |= jM ƒ  D]^ \ }X }Y |Y \ }> }F | j. |F ˆ  j% t" j# d ƒ g ƒ }Z | j- | j5 |Z ƒ ˆ jN |X ƒ ƒ q3Wˆ  jK jL | j ƒ d, S(-   sF   
    Adds the call to the gufunc function from the main function.
    i   (   t   build_gufunc_wrapperR(   t   _launch_threadst   make_parallel_loops   args = s   outer_sig = s   loop_ranges = t	   expr_argst   expr_arg_typesRÐ   t   cachet
   is_parforss   parallel function = c         ` s9   t  |  t j ƒ r" ˆ j |  j ƒ Sˆ  j t j |  ƒ Sd  S(   N(   Ri   R   RX   t   loadvarRZ   t   get_constantR   Ry   (   RÞ   (   RI   R˜   (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt
   load_range¡  s    s'   call_parallel_gufunc loop_ranges[{}] = s   loop range[{}]: %d %d (%d)
i   i    s%   Parfor has potentially negative startt   sizeRZ   t   dimsi   R>   t   do_scheduling_signedt   do_scheduling_unsigneds   sched[s   ] = s   %d s   
t   pargss   var =s   gu_sig =s   type =s   i =s   var = s    type = s
   dim_sym = s   , i = s    = %d
t   pshapet   pstepss   before calling kernel %p
s   after calling kernel %p
N(O   RI   t   builderRH   R¡  R(   R¢  R"   RO   RP   RC   t   return_typet   recvrt   pysigR	   t   normalize_signaturet   libraryt   get_functionRK   t   llvm_func_nameR„   R€   RZ   t   _ensure_finalizedRd   Re   R`   R^  R   t   printft   lct   Typet   intt   pointert   get_value_typeR   Rp   Ry   R©  RT   t   get_abi_sizeofR•   t   signedt   alloca_oncet   sextt   subt   storet   gept   functiont   modulet   get_or_insert_functionRx   R¨  RZ  t   loadt   bitcastRï   t
   make_arrayt   unpack_tuplet   stridesRl   R4   t   dataRi   t   ArrayCompatibleRg   t   booleant   get_data_typeRí   Rj   Rk   RL   R_   t   mult   get_null_valuet   voidt   active_code_libraryt   add_linking_libraryR  t   getvar([   R˜   t   cresRÐ   t	   outer_sigR¤  R¥  RÑ   t   redvarst   reddictt
   redarrdictRR   RÇ   RW   R²  R¡  R(   R¢  RC   R³  t	   llvm_funct   sint   soutt   infot   wrapper_nameRª  t   num_dimR¦   R‡   Rˆ   R‰   t   byte_tt
   byte_ptr_tt   byte_ptr_ptr_tt   intp_tt   uintp_tt
   intp_ptr_tt   uintp_ptr_tt   zerot   onet   one_typet   sizeof_intpt	   sched_sigt
   sched_typet   sched_ptr_typet
   dim_startst	   dim_stopst
   sched_sizeR>   t
   debug_flagt   scheduling_fntyt   do_schedulingRG  R¤   R£   t   ninoutsRµ   t   all_argst   num_argst   num_inpst   array_stridest
   red_shapest   rv_to_arg_dictRü   Rñ   t   atyt   dstt   aryRÏ  t
   ary_shapest   typt   rv_argt   ptrt   sig_dim_dictt
   occurancest   gu_sigt   dim_symt   shapest   nshapest	   num_stepst   stepsRA  t
   red_stridet   sizeoft   stepsizet   rsRÐ  t   fntyt   fnt   kRÞ   t   only_elem_ptr(    (   RI   R˜   s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyRŠ   z  sè   			
			
					 			)	)*	


("6("00 !"% 	"		"	 
	(		$&(]   t
   __future__R    R   R   t   astRM   t   collectionsR   t	   linecachet   osR‹   R=   Rm   t   llvmlite.llvmpy.coret   llvmpyt   coreR¼  t   llvmlite.ir.valuesR   R–   t   livR[   RO  R   R   R   R   R	   R
   R   t   numba.ir_utilsR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   numba.analysisR   R   R   R    R_  R!   R"   t   numba.targets.cpuR#   t	   numba.sixR$   t   numba.parforR%   R&   R  RT  t   errorsR'   R)   t   lower_extensionsR#  R…   R   R  R  R  R  R"  R$  R%  R'  R1  R3  R4  R=  R?  Rf   RD  RI  R‚   RŸ  R™  RV  RŠ   (    (    (    s4   lib/python2.7/site-packages/numba/npyufunc/parfor.pyt   <module>   s`   :p"	ÿ e	B						>		
					)					ÿ “			