
t[c           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z e Z d  d l m Z m Z m	 Z	 d  d l
 m Z e j Z e j d d k  r e Z e Z n e j Z e j Z i d d 6d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6Z i d d 6d	 d 6d d
 6d d 6d d 6d d 6d d 6d d 6Z i d e 6d	 e 6d e 6d e 6d e 6d e 6d e 6Z e j Z e j Z e e j Z d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 g Z e j d d1 k rd2 e d <d e d2 <d e e  <n  e j!   Z" d3 e# f d4     YZ$ d5   Z% d6   Z& d7   Z' d8 e# f d9     YZ( d: e( f d;     YZ) d<   Z* d=   Z+ d d>  Z- d?   Z. d@   Z/ dA   Z0 dB   Z1 dC   Z2 dD   Z3 dE   Z4 dF   Z5 dG   Z6 dH   Z7 dI   Z8 dJ d\ dL f dM e e9 dN f dN f g Z: dO dP  Z; d] i  dQ  Z< d^ dR  Z= dS   Z> dT   Z? dU   Z@ d d dV  ZA e dW  ZB e dW  ZC i  aD e jE   ZF d d d dX dY dZ  ZG d d[  ZH d S(_   iN(   t   interpretert   expressionst   use_vml(   t	   CacheDicti    i   t   boolt   bt   intt   it   longt   lt   floatt   ft   doublet   dt   complext   ct   bytest   st   nonet   nt   divt   invt   powt   sqrtt   sint   cost   tant   arcsint   arccost   arctant   sinht   cosht   tanht   arcsinht   arccosht   arctanht   logt   log1pt   log10t   expt   expm1t   absolutet	   conjugatet   arctan2t   fmodt   ceilt   floori   t   strt   ASTNodec           B   s   e  Z d  Z d d d d g Z d d d d d  Z d   Z d	   Z d
   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z RS(   s  Abstract Syntax Tree node.

    Members:

    astType      -- type of node (op, constant, variable, raw, or alias)
    astKind      -- the type of the result (bool, float, etc.)
    value        -- value associated with this node.
                    An opcode, numerical value, a variable name, etc.
    children     -- the children below this node
    reg          -- the register assigned to the result for this node.
    t   astTypet   astKindt   valuet   childrent   generict   unknownc         C   sD   t  j |   | |  _ | |  _ | |  _ t |  |  _ d  |  _ d  S(   N(	   t   objectt   __init__R1   R2   R3   t   tupleR4   t   Nonet   reg(   t   selfR1   R2   R3   R4   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR8   ^   s    			c         C   s   |  j  d k r |  j }  n  | j  d k r6 | j } n  t | t  sI t Sx3 |  j D]( } t |  |  t | |  k rS t SqS Wt S(   Nt   alias(   R1   R3   t
   isinstanceR0   t   Falset   cmpnamest   getattrt   True(   R<   t   othert   name(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   __eq__g   s    c         C   sj   |  j  d k rS |  j | j k rC t j |  j  t j | j  k  S|  j | j k  St d |  j    d  S(   Nt   constants'   Sorting not implemented for astType: %s(   R1   R2   t   numpyt   arrayR3   t	   TypeError(   R<   RC   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   __lt__s   s
    "c         C   s=   |  j  d k r |  j }  n  t |  j  |  j |  j |  j f  S(   NR=   (   R1   R3   t   hashR2   R4   (   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   __hash__   s    c         C   s&   d |  j  |  j |  j |  j |  j f S(   Ns   AST(%s, %s, %s, %s, %s)(   R1   R2   R3   R4   R;   (   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   __str__   s    c         C   s   d t  |   S(   Ns   <AST object at %s>(   t   id(   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   __repr__   s    c         C   s   |  j  |  j |  j |  j f S(   N(   R1   R2   R3   R4   (   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   key   s    c         C   s   t  |  j S(   N(   t   kind_to_typecodeR2   (   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   typecode   s    c         c   s9   x- |  j  D]" } x | j   D] } | Vq Wq
 W|  Vd  S(   N(   R4   t   postorderWalk(   R<   R   t   w(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyRS      s    c         g   s>   t  |  } x+ |  j   D] } | j | k r | Vq q Wd  S(   N(   t   setRS   R1   (   R<   t   astTypesRT   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   allOf   s    N(    (   t   __name__t
   __module__t   __doc__R@   R:   R8   RE   RJ   RL   RM   RO   RP   RR   RS   RW   (    (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR0   P   s   								c         C   s8   t  |  j |  j |  j g  |  j D] } t |  ^ q  S(   s   Take an expression tree made out of expressions.ExpressionNode,
    and convert to an AST tree.

    This is necessary as ExpressionNode overrides many methods to act
    like a number.
    (   R0   R1   R2   R3   R4   t   expressionToAST(   t   exR   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR[      s    c         c   s   d } |  s d Vn |  d | k rs | j  |  d  } xu | | D]* } x! t |  d  D] } | | VqY WqB Wn< |  d d k r x) t |  d  D] } d | Vq Wn |  Vd S(   sS   Generate all possible signatures derived by upcasting the given
    signature.
    t   bilfdct    i    i   R   N(   t   indext   sigPerms(   R   t   codest   startt   xt   y(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR`      s    c         C   s  t  |  j  } |  j d k r|  j   } d j d   t  |  j  D  } x t |  D]7 } |  j d | | j d  } | t j	 k rY PqY qY Wx t |  D]n } |  j d | | j d  } | t j
 k r d | | j d  } | t d d t j
 |  g 7} Pq q Wt d	 |  j d | |   x t t | |   D] \ } \ } }	 | |	 k rHt |	 }
 | | j d
 k rt d
 |
 | | j  | | <qd } t d |
 | | | g  | | <qHqHWn |  j } |  j } t |  j |  j | g  | D] } t |  ^ q S(   s   Assign appropiate types to each node in the AST.

    Will convert opcodes and functions to appropiate upcast version,
    and add "cast" ops if needed.
    t   opR^   c         s   s   |  ] } | j    Vq d  S(   N(   RR   (   t   .0Rc   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pys	   <genexpr>   s    t   _t   asciis   func_%snt   rawR   s&   couldn't find matching opcode for '%s'RF   t   cast(   t   listR4   R1   RR   t   joinR`   R3   t   encodeR    t   opcodest	   funccodesR0   t   NotImplementedErrort	   enumeratet   zipt   typecode_to_kindR2   t   typeCompileAst(   t   astR4   t   retsigt   basesigt   sigR3   t   funcnameR   t   havet   wantt   kindt   opnameR   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyRt      s:    "(
 *		t   Registerc           B   s,   e  Z d  Z e d  Z d   Z d   Z RS(   sM  Abstraction for a register in the VM.

    Members:
    node          -- the AST node this corresponds to
    temporary     -- True if this isn't an input or output
    immediate     -- not a register, but an immediate value
    n             -- the physical register number.
                     None if no number assigned yet.
    c         C   s(   | |  _  | |  _ t |  _ d  |  _ d  S(   N(   t   nodet	   temporaryR?   t	   immediateR:   R   (   R<   t   astnodeR   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR8      s    			c         C   s;   |  j  r d } n d } d | |  j j |  j j |  j f S(   Nt	   TemporaryR~   s   %s(%s, %s, %s)(   R   R   R1   R2   R   (   R<   RD   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyRM      s
    		c         C   s
   |  j    S(   N(   RM   (   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyRO      s    (   RX   RY   RZ   R?   R8   RM   RO   (    (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR~      s   		t	   Immediatec           B   s    e  Z d  Z d   Z d   Z RS(   sQ   Representation of an immediate (integer) operand, instead of
    a register.
    c         C   s   t  j |  |  t |  _ d  S(   N(   R~   R8   RB   R   (   R<   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR8   	  s    c         C   s   d |  j  j f S(   Ns   Immediate(%d)(   R   R3   (   R<   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyRM     s    (   RX   RY   RZ   R8   RM   (    (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR     s   	c   
      C   s  t  j j   } zXt  j j |  | j d t  rC t j j } n d } t	 |  d d |  } i  } x | j
 D]} } | d k r d	 | | <qn | d k r t | | <qn | d k r t | | <qn | j | t  } t  j | t |  | | <qn W| j t  j  t | |  }	 t  j |	  r;t  j |	 t  j |	   }	 n+ t |	 t  j  sft d t |	    n  Wd	 t  j j |  X|	 S(
   s>   Given a string, convert it to a tree of ExpressionNode's.
    t   truedivi    s   <expr>t   evalR:   RB   R?   s   unsupported expression type: %sN(   R   t   _contextt   get_current_contextt   set_new_contextt   getR?   t
   __future__t   divisiont   compiler_flagt   compilet   co_namesR:   RB   t   default_typet   VariableNodet   type_to_kindt   updatet	   functionsR   t
   isConstantt   ConstantNodet   getKindR>   t   ExpressionNodeRI   t   type(
   R   t   typest   contextt   old_ctxt   flagsR   t   namesRD   t   tR\   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   stringToExpression  s2    c            s    d } t    f d   | D  S(   Nt   sum_t   prod_t   min_t   max_c         3   s!   |  ] }   j  j |  Vq d  S(   N(   R3   t
   startswith(   Rf   t   p(   Ru   (    s1   lib/python2.7/site-packages/numexpr/necompiler.pys	   <genexpr>7  s    (   R   R   R   R   (   t   any(   Ru   t   prefixes(    (   Ru   s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   isReduction5  s    c         C   s   i  } x$ |  j  d  D] } | | | j <q Wt | j    } | ry | t |  k rp t d | | f   n  | } n t |  } | j   g  | D] } | | ^ q } | S(   s>   Derive the input order of the variables in an expression.
    t   variables;   input names (%s) don't match those found in expression (%s)(   RW   R3   RU   t   keyst
   ValueErrorRk   t   sort(   Ru   t   input_ordert	   variablest   at   variable_namest   ordered_namest   vt   ordered_variables(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   getInputOrder:  s    	
c         C   sV   | d k r t  j |   St j d d k rH t |  t  rH |  j d  St | |   S(   NR
   i    i   Rh   (   RG   t   float32t   syst   version_infoR>   R/   Rm   t   kind_to_type(   Rc   R|   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   convertConstantToKindP  s
    "c         C   sG   t  |  j d   } g  | D] } t | j | j  ^ q } | | f S(   s   
    RAM: implemented magic method __lt__ for ASTNode to fix issues
    #88 and #209. The following test code works now, as does the test suite.
    import numexpr as ne
    a = 1 + 3j; b = 5.0
    ne.evaluate( 'a*2 + 15j - b' )
    RF   (   t   sortedRW   R   R3   R2   (   Ru   t   constants_orderR   t	   constants(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   getConstantsY  s    %c   	      C   s   i  } x- t  |  D] \ } \ } } } | | | <q Wg  |  D] } | | j | f ^ q= } | j   g  | D] } | d ^ qm S(   Ni   (   Rq   R3   R   (	   t   nodest   ordert	   order_mapR   Rg   R   R   t	   dec_nodesR   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   sortNodesByOrderg  s    "&
c         C   sZ   i  } xM |  D]E } | j    } | | k r; | | | _ q | |  | _ | | <q Wd S(   s4   Assign new registers to each of the leaf nodes.
    N(   RP   R;   (   t   inodest   registerMakert   leafRegistersR   RP   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   assignLeafRegistersp  s    c         C   s*   x# |  D] } | | d t  | _ q Wd S(   s<   Assign temporary registers to each of the branch nodes.
    R   N(   RB   R;   (   R   R   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   assignBranchRegisters|  s    c         C   s   i  } g  } xb |  j  d  D]Q } | | k rc | | } d | _ | | _ d | _ | j |  q | | | <q Wx6 | D]. } x% | j j d k r | j j | _ q Wqx W| S(   s&   Common subexpression elimination.
    Re   R=   (    (   RW   R1   R3   R4   t   append(   Ru   t   seent   aliasesR   t   target(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   collapseDuplicateSubtrees  s    
			c         C   s  g  |  j    D] } | j j r | ^ q } t d   | D  } t d   | D  } | r} | d |  k	 r} | |  g } n | } xE | D]= } x4 | j D]) } | j j r | | j j |  q q Wq Wt g  t D] } | t   f ^ q  } x | D] } x] | j D]R } | j }	 |	 j r
| |	 }
 |
 j |  |
 s\| |	 j	 j
 j |	  q\q
q
W| | j
 r | | j
 j   }	 | | j | |	 <|	 | _ q q Wd S(   sS   Attempt to minimize the number of temporaries needed, by
    reusing old ones.
    c         s   s!   |  ] } | j  t   f Vq d  S(   N(   R;   RU   (   Rf   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pys	   <genexpr>  s    c         s   s.   |  ]$ } | t  d    | j D  f Vq d S(   c         s   s$   |  ] } | j  j r | j  Vq d  S(   N(   R;   R   (   Rf   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pys	   <genexpr>  s    N(   RU   R4   (   Rf   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pys	   <genexpr>  s   iN(   RS   R;   R   t   dictR4   t   addt   scalar_constant_kindsRU   t   discardR   R2   t   pop(   Ru   R   R   t   users_oft	   node_regst   nodes_to_checkR   t   tct   unusedR;   t   users(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   optimizeTemporariesAllocation  s0    +	(		
!c         C   s;   x* t  |   D] \ } } | | | j _ q W| t |   S(   s6   Given an order of nodes, assign register numbers.
    (   Rq   R;   R   t   len(   R   Rb   R   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   setOrderedRegisterNumbers  s    c         C   s   d } d } g  } x |  j    D] } | j d k rM | j |  | j } n  | j j rn | j | j _ q n  | j } | j d k r | | | _ | d 7} | | j j	   7} q q Wx | D] } | j j | _ q W| | | f S(   ss   Assign register numbers for temporary registers, keeping track of
    aliases and handling immediate operands.
    i    R^   R=   i   N(
   RS   R1   R   R3   R;   R   R   R:   R   RR   (   Ru   Rb   R   t	   signatureR   R   R;   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt    setRegisterNumbersForTemporaries  s$    	
c         C   sO   g  |  j  d  D]; } | j | j f t g  | j D] } | j ^ q2  ^ q S(   s  Convert an AST to a three address form.

    Three address form is (op, reg1, reg2, reg3), where reg1 is the
    destination of the result of the instruction.

    I suppose this should be called three register form, but three
    address form is found in compiler theory.
    Re   (   RW   R3   R;   R9   R4   (   Ru   R   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   convertASTtoThreeAddrForm  s    	c            sY   d     d d   f d    f d   } d j g  |  D] } | |  ^ q:  } | S(   s`   Given a three address form of the program, compile it a string that
    the VM understands.
    c         S   si   |  d  k r d S|  j d k  r5 t d |  j   n0 t j d d k  rU t |  j  St |  j g  Sd  S(   Ns   i    s%   negative value for register number %si   (   R:   R   R   R   R   t   chrR   (   R;   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   nToChr  s    c            sP   t  t j |   j d  }   |  }   |  }   |  } | | | | S(   NRh   (   R   R    Rn   Rm   (   t   opcodet   storet   a1t   a2t   copt   cst   ca1t   ca2(   R   (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   quadrupleToString  s
    c            s   x  t  |   d k  r" |  d 7}  q W|  d  \ } } } }   | | | |  } | g } |  d }  x4 |  r   d |  d   } | j |  |  d }  qd Wd j |  S(   Ni   t   noopi   R^   (   N(   R   R:   R   Rl   (   t   argsR   R   R   R   R   R	   (   R   (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   toString   s    	
	R^   N(   R:   Rl   (   t   programR   R   t   prog_str(    (   R   R   s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   compileThreeAddrForm  s
    	(t   optimizationt   moderatet
   aggressiveR   t   autoi   c   	      C   s   |  j    } i  } xX t D]P \ } } } | j | |  } | | k rS | | | <q t d | | f   q W| r t d | j   d   n  | d d k r t j | d  j } | j d d   t
 j k | d <n  | S(   Ns   '%s' must be one of %ss   Unknown keyword argument '%s'i    R   R   i   R   (   t   copyt   context_infoR   R   t   popitemR   t	   _getframet	   f_globalsR   R:   R   R   (	   t   kwargst   frame_depthR   R   RD   t   allowedt   defaultR3   t   caller_globals(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt
   getContext  s    "c            s  t  |    g  | D] \ } } | ^ q } t |  t t f  rU t |    |  }  n  t |   } |  j d k r t d d d d |  j d | f } n  t	 |  } t
 |  } t | j d  t  t | j d d  t  t | j d  t  x | D] } | j j | _ q Wt | |  } t |  \ }	 }
 t |  rPt | j _ n  t |  t | j _ d	 } d	 | j _ | d
 } t | |  } t |	 |  } t | |  \ } } t |  } t g  | D] } | j ^ q } d j   f d   | D  } | | | |
 | f S(   s4   Compile the expression to an intermediate form.
    Re   R3   R   R2   R4   Ri   R   RF   i    i   R^   c         3   s%   |  ] } t    j | t  Vq d  S(   N(   t   type_to_typecodeR   R   (   Rf   Rc   (   R   (    s1   lib/python2.7/site-packages/numexpr/necompiler.pys	   <genexpr>Z  s   (   R   R>   R/   t   unicodeR   R[   R1   R0   R2   Rt   R   R   RW   R   R~   R   R3   R;   R   R   R   R?   R   R   R   R   R   R   R9   Rl   (   R\   R   R   RD   t   type_R   Ru   R   R   R   R   t   r_outputt   r_inputst   r_constantst   r_tempst   r_endt   tempsigt   threeAddrProgramt   input_names(    (   R   s1   lib/python2.7/site-packages/numexpr/necompiler.pyt
   precompile*  s>    '

"c   
      K   sj   t  | d d } t |  | |  \ } } } } } t |  }	 t j | j d  | j d  |	 | |  S(   sY  
    Compile an expression built using E.<variable> variables to a function.

    ex can also be specified as a string "2*a+3*b".

    The order of the input variables and their types can be specified using the
    signature parameter, which is a list of (name, type) pairs.

    Returns a `NumExpr` object containing the compiled function.
    R   i   Rh   (   R   R
  R   R    t   NumExprRm   (
   R\   R   R   R   R  t   inputsigR  R   R	  R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyR  _  s    !c            s'  i   x" t  j D] } |  t  j | <q Wd t   j    t   j        f d   } g  } x t d t   j  d  D] } t j d d k  r  j	 t
   j |   } n  j	   j |  } | | d  } | | d  } | | d  } | j | | | | f  q W| S(   sR   
    Given a NumExpr object, return a list which is the program disassembled.
    i   c            sp  t  j d d k  rI t   j |  |  }  j t   j |    } n'   j |  | }  j   j |   } y | j d  d | d } Wn t k
 r d  SXt  j d d k r t | g  } n  | d k r d  S| d k rh| d k r d S|  k  r#d	 |   j	 | d f j
 d
  S|  k  rQd |   j |  f j
 d
  Sd | f j
 d
  Sn | Sd  S(   Ni    i   Rg   i   i   i   R   t   r0s   r%d[%s]Rh   s   c%d[%s]s   t%d(   R   R   t   ordR   R   t   splitt
   IndexErrorR:   R   R	  Rm   R   (   t   pct   offsett   argRe   t   code(   t   nexR  R  t   rev_opcodes(    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   getArg  s,    ""i    i   i   i   (   R    Rn   R   R   R   t   rangeR   R   R   R   R  R   (   R  Re   R  t   sourceR  t   destt   arg1t   arg2(    (   R  R  R  R  s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   disassembley  s     "c         C   s   |  j  j } | d k r t S| d k rd |  j  j d k r> t S| d k r` |  j  j d k r` t St S| d k r |  j  j d k r t St S| d k r t S| d k r t	 St
 d |  j  j   d  S(	   NR   t   iui   t   uR   R   t   Ss   unknown type %s(   t   dtypeR|   R   t   itemsizet   long_t   int_R   R
   R   R   R   RD   (   R   R|   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   getType  s$    c         C   s   t  |  i  |  } t |  } t | d   } t s< t } nE xB | j   D]. } | j d k rI | j t	 k rI t
 } PqI qI Wt } g  | D] } | j ^ q | f S(   NRe   (   R   R[   R   R:   R   R?   RS   R1   R3   t   vml_functionsRB   (   t   textR   R\   Ru   R   t   ex_uses_vmlR   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   getExprNames  s    	c   	      C   s   t  j d  } t } | d k r3 | j } t } n  z | j } | d k rT | } n  | oc | | k	 } g  } xP |  D]H } y | | } Wn t k
 r | | } n X| j t	 j
 |   qs WWd | r | j   n  X| S(   s%   Get the arguments based on the names.i   N(   R   R   R?   R:   t   f_localsRB   R   t   KeyErrorR   RG   t   asarrayt   clear(	   R   t
   local_dictt   global_dictt
   call_framet   clear_local_dictt   frame_globalst	   argumentsRD   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   getArguments  s(    				i   t   Kt   safec         K   sv  t  |  t t f  s$ t d   n  t | d d } |  t t | j     f } | t k rv t	 |  |  t | <n  t | \ }	 }
 t
 |	 | |  } g  t |	 |  D] \ } } | t |  f ^ q } | t |  f } y t | } Wn+ t k
 rt |  | |  } t | <n Xi | d 6| d 6| d 6|
 d 6} t d | d	 |	 d
 |  a t  | | |   SWd QXd S(   s  Evaluate a simple array expression element-wise, using the new iterator.

    ex is a string forming an expression, like "2*a+3*b". The values for "a"
    and "b" will by default be taken from the calling function's frame
    (through use of sys._getframe()). Alternatively, they can be specifed
    using the 'local_dict' or 'global_dict' arguments.

    Parameters
    ----------

    local_dict : dictionary, optional
        A dictionary that replaces the local operands in current frame.

    global_dict : dictionary, optional
        A dictionary that replaces the global operands in current frame.

    out : NumPy array, optional
        An existing array where the outcome is going to be stored.  Care is
        required so that this array has the same shape and type than the
        actual outcome of the computation.  Useful for avoiding unnecessary
        new array allocations.

    order : {'C', 'F', 'A', or 'K'}, optional
        Controls the iteration order for operands. 'C' means C order, 'F'
        means Fortran order, 'A' means 'F' order if all the arrays are
        Fortran contiguous, 'C' order otherwise, and 'K' means as close to
        the order the array elements appear in memory as possible.  For
        efficient computations, typically 'K'eep order (the default) is
        desired.

    casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
        Controls what kind of data casting may occur when making a copy or
        buffering.  Setting this to 'unsafe' is not recommended, as it can
        adversely affect accumulations.

          * 'no' means the data types should not be cast at all.
          * 'equiv' means only byte-order changes are allowed.
          * 'safe' means only casts which can preserve values are allowed.
          * 'same_kind' means only safe casts or casts within a kind,
            like float64 to float32, are allowed.
          * 'unsafe' means any data conversions may be done.
    s#   must specify expression as a stringR   i   t   outR   t   castingR(  R\   t   argnamesR   N(   R>   R/   R   R   R   R9   R   t   itemst   _names_cacheR)  R4  Rr   R%  t   _numexpr_cacheR+  R  R   t   _numexpr_lastt   evaluate_lock(   R\   R.  R/  R7  R   R8  R   R   t   expr_keyR   R(  R3  RD   R  R   t   numexpr_keyt   compiled_ex(    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   evaluate  s(    -1
c         C   so   y t  d } Wn t k
 r- t d   n Xt  d } t | |   } t  d } t  | | |   SWd QXd S(   s  Re-evaluate the previous executed array expression without any check.

    This is meant for accelerating loops that are re-evaluating the same
    expression repeatedly without changing anything else than the operands.
    If unsure, use evaluate() which is safer.

    Parameters
    ----------

    local_dict : dictionary, optional
        A dictionary that replaces the local operands in current frame.

    R\   s)   not a previous evaluate() execution foundR9  R   N(   R=  R+  t   RuntimeErrorR4  R>  (   R.  RA  R9  R   R   (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   re_evaluateE  s    

(   R   R   R   (    (    (I   R   R   RG   t	   threadingR?   t   is_cpu_amd_intelt   numexprR    R   R   t   numexpr.utilsR   R   R   R   R$  R   R#  t   int32t   int64Rs   RQ   R   R
   R   R   R   R   R   t   default_kindR   R&  R/   R   R   R7   R0   R[   R`   Rt   R~   R   R   R   R:   R   R   R   R   R   R   R   R   R   R   R   R   RB   R   R   R
  R  R  R%  R)  R4  R;  R<  R=  t   LockR>  RB  RD  (    (    (    s1   lib/python2.7/site-packages/numexpr/necompiler.pyt   <module>   s   							

N			+	$										!				+5	4		#G