ó
£áSc           @` sÄ  d  Z  d d l m Z m Z m Z d d d g Z d d l Z d d l Z d d l Z d d l	 Z	 d d d	 g Z
 d
 d d d d d d d g Z d d	 d d d d d d d d d d d d g Z e e Z i  Z x+ e D]# Z d e Z e j e ƒ e e <qÕ Wd d l Z d e j e j e j Z d „  Z d  „  Z e d! „ Z d" „  Z d# „  Z d$ „  Z e d% „ Z d& „  Z e j  j! e d' „ Z" d( „  Z# e j  j! e d) „ Z$ e% d* k rÀe e j& ƒ n  d S(+   s¯  
This module adds the default axis argument to code which did not specify it
for the functions where the default was changed in NumPy.

The functions changed are

add -1  ( all second argument)
======
nansum
nanmax
nanmin
nanargmax
nanargmin
argmax
argmin
compress 3


add 0
======
take     3
repeat   3
sum         # might cause problems with builtin.
product
sometrue
alltrue
cumsum
cumproduct
average
ptp
cumprod
prod
std
mean

i    (   t   divisiont   absolute_importt   print_functiont   convertfilet
   convertallt   converttreeNt   compresst   taket   repeatt   nansumt   nanmaxt   nanmint	   nanargmaxt	   nanargmint   argmaxt   argmint   sumt   productt   sometruet   alltruet   cumsumt
   cumproductt   averaget   ptpt   cumprodt   prodt   stdt   means   %s\s*[(]t   _c         C` sÇ  d } | t  k r d } n d } d } d } xjt | j |  ƒ D]U} d } | j ƒ  \ }	 }
 |  |	 d t k ry qA n  |  |	 d d k r|  |	 d |	 d !d k r|  |	 d |	 d !d k r|  |	 d	 |	 d !d
 k r|  |	 d |	 d !d k r|  |	 d |	 d !d k rqA n  |  |	 d d k r˜|	 d } x |  | d k rX| d 8} q;W|  | d | d !d k sA |  | d | d !d k r˜qA q˜n  |
 } d } d } t |  ƒ } x£ | r[| | k rÕd } Pn  |  | d k rò| d 8} n\ |  | d k r| d 7} n? | d k rN|  | d k rN| d 7} | | k rNd } PqNn  | d 7} q¹W| rhqA n  | d 7} d | |  | | d !| f } | } qA W| s©|  } n d | |  | f } | | f S(   Ni    i   t    t   .i   t   numpyi   t   Ni	   t   numarrayi   t   numerixt   Numerics   	t    t   defi   t   classt   )t   (t   ,s   %s%s,%s)s   %s%s(   s   	R$   (   s   	R$   (   t   _args3t   func_ret   finditert   spant
   disallowedt   len(   t   fstrt   namet   replt   altert   allowed_commat   newcodet   lastt   objt   nochanget   startt   endt   kt   stackt   ncommasR    (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt	   _add_axisA   sh    	
		


	c         C` så  d } d } |  j  | ƒ } | d k r¥ d } x: | D]2 } |  j  d | | ƒ } | d k r4 d } Pq4 q4 W| r¥ d |  |  d |  | t | ƒ f }  | d 7} q¥ n  t j d ƒ } | j |  ƒ }	 t |	 ƒ d k r„x¬ |	 D]¡ }
 d } x= | D]5 } |  j  d |
 | f ƒ } | d k rï d } Pqï qï W| rÜ d	 |
 } |  j  | ƒ } d |  |  d
 |
 |  | t | ƒ f }  | d 7} qÜ qÜ Wn  d } |  j  | ƒ } | d k r3d } xJ | D]B } |  j  | | ƒ } | d k r²|  | d t k r²d } Pq²q²W| r3d |  |  d |  | t | ƒ f }  | d 7} q3n  d } d } t | ƒ } x�t rÚ|  j  | | ƒ } | d k  rvPn  | | 7} | d } d } xN | rà|  | d k r¶| d 7} n |  | d k rÓ| d 8} n  | d 7} q“W|  | | !} d } | j d d ƒ } | j d d ƒ } g  | j d ƒ D] } | j	 ƒ  ^ q(} g  } x7 | D]/ } | | k rM| j
 | ƒ | j | ƒ qMqMWt | ƒ d k rNd |  |  d d j | ƒ d d j | ƒ |  | f }  | d 7} qNqNW|  | f S(   Ni    s   import numpys   numpy.%si   s   %s%s%ss    import numpy.oldnumeric as numpys   import numpy as ([A-Za-z0-9_]+)s   %s.%ss   import numpy as %ss   import numpy.oldnumeric as %ss   from numpy import *s   from numpy.oldnumeric import *s   from numpy imports   \s   
R$   R   R)   s
   %s%s
%s
%ss   from numpy import %ss   , s   from numpy.oldnumeric import %s(   t   findR/   t   ret   compilet   findallR.   t   Truet   replacet   splitt   stript   removet   appendt   join(   R0   t   namest   numt	   importstrt   indt   foundR1   t   ind2t   importret   modulest   moduleR    t   ptrR<   t   substrt   xt   importnamest   addnames(    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   _import_changey   s¢    

 
	

	(c         C` s£   d } | s| x0 t  D]( } t |  | d ƒ \ }  } | | 7} q Wx0 t D]( } t |  | d ƒ \ }  } | | 7} qF W|  | f St |  t  t ƒ \ }  } |  | f Sd  S(   Ni    s   axis=-1s   axis=0(   t   _funcm1R>   t   _func0RX   (   R0   t   import_changet   totalR1   RK   (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   add_axisà   s    
c         C` s*   t  |  d ƒ } | j | ƒ | j ƒ  d  S(   Nt   w(   t   filet   writet   close(   R1   t   filestrt   fid(    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   makenewfileï   s    c         C` s&   t  |  ƒ } | j ƒ  } | j ƒ  | S(   N(   R_   t   readRa   (   R1   Rc   Rb   (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   getfileô   s    
c         C` s-   t  j j |  ƒ \ } } t | d | ƒ d  S(   Ns   .orig(   t   ost   patht   splitextRd   (   R1   R0   t   baset   ext(    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   copyfileú   s    c         C` sh   t  |  ƒ } t | | ƒ \ } } | d k rd t d |  ƒ t |  | ƒ t |  | ƒ t j j ƒ  n  d S(   sŸ   Convert the filename given from using Numeric to using NumPy

    Copies the file to filename.orig and then over-writes the file
    with the updated code
    i    s	   Changing N(   Rf   R]   t   printRl   Rd   t   syst   stdoutt   flush(   t   filenameR[   Rb   t   newstrR\   (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyR   ÿ   s    c         C` s   |  d } t  | ƒ d  S(   Ni   (   R   (   t   argsRq   (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   fromargs  s    
c         C` s@   t  j  t j j |  d ƒ ƒ } x | D] } t | | ƒ q% Wd S(   sÖ   Convert all .py files in the directory given

    For each file, a backup of <usesnumeric>.py is made as
    <usesnumeric>.py.orig.  A new file named <usesnumeric>.py
    is then written with the updated code.
    s   *.pyN(   t   globRg   Rh   RI   R   (   t   direcR[   t   filest   afile(    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyR     s    c         C` s   t  | d |  ƒd  S(   NR[   (   R   (   t   argt   dirnamet   fnames(    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   _func  s    c         C` s   t  j j |  t | ƒ d S(   s-   Convert all .py files in the tree given

    N(   Rg   Rh   t   walkR|   (   Rv   R[   (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyR     s    t   __main__('   t   __doc__t
   __future__R    R   R   t   __all__Rn   Rg   R@   Ru   R*   RY   RZ   t   _allR+   R1   t   _astrRA   t   stringt	   uppercaset	   lowercaset   digitsR.   R>   RX   t   FalseR]   Rd   Rf   Rl   R   Rt   Rh   t   curdirR   R|   R   t   __name__t   argv(    (    (    s[   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/fix_default_axis.pyt   <module>$   s@   

	8	g					