ó
£áSc        
   @` sô  d  Z  d d l m Z m Z m Z d d d d g Z d d l Z d d l Z d d l Z d d l	 Z	 d d	 g Z
 d
 g Z d d d d d d d d d d g
 Z i d d 6d d 6d d 6d d 6Z i  Z i  Z x1 e D]) Z d e Z e j e e j ƒ e e <qÒ Wx1 e
 D]) Z d e Z e j e e j ƒ e e <qWx1 e D]) Z d e Z e j e e j ƒ e e <q:Wx7 e j ƒ  D]) Z d  e Z e j e e j ƒ e e <qtWd! „  Z e j d" ƒ Z d# „  Z i  Z d$ d% d& d' d( d) d* g Z x+ e D]# Z d+ e Z e j e ƒ e e <qêWd, „  Z d- „  Z e j d. ƒ Z e j d/ ƒ Z d0 „  Z d d l  Z  d1 „  Z! d2 „  Z" d3 d4 „ Z# d5 „  Z$ e j% j& d3 d6 „ Z' e j d7 ƒ Z( e j% j& d d3 d8 „ Z* d9 „  Z+ e j% j& d: „ Z, e- d; k rðe$ e j. ƒ n  d S(<   s•  
This module converts code written for Numeric to run with numpy

Makes the following changes:
 * Changes import statements (warns of use of from Numeric import *)
 * Changes import statements (using numerix) ...
 * Makes search and replace changes to:
   - .typecode()
   - .iscontiguous()
   - .byteswapped()
   - .itemsize()
   - .toscalar()
 * Converts .flat to .ravel() except for .flat = xxx or .flat[xxx]
 * Replace xxx.spacesaver() with True
 * Convert xx.savespace(?) to pass + ## xx.savespace(?)

 * Converts uses of 'b' to 'B' in the typecode-position of
   functions:
   eye, tri (in position 4)
   ones, zeros, identity, empty, array, asarray, arange,
   fromstring, indices, array_constructor (in position 2)

   and methods:
   astype --- only argument
    -- converts uses of '1', 's', 'w', and 'u' to
    -- 'b', 'h', 'H', and 'I'

 * Converts uses of type(...) is <type>
   isinstance(..., <type>)

i    (   t   divisiont   absolute_importt   print_functiont   convertfilet
   convertallt   converttreet
   convertsrcNt   eyet   trit   astypet   onest   zerost   identityt
   fromstringt   indicest   emptyt   arrayt   asarrayt   aranget   array_constructort   bt   1t   ht   st   Ht   wt   It   us.   (%s\s*[(][^,]*?[,][^'"]*?['"])b(['"][^)]*?[)])s@   (%s\s*[(][^,]*?[,][^,]*?[,][^,]*?[,][^'"]*?['"])b(['"][^)]*?[)])s&   (.%s\s*[(][^'"]*?['"])b(['"][^)]*?[)])s+   (.astype\s*[(][^'"]*?['"])%s(['"][^)]*?[)])c         C` sh   x, t  t t D] } t | j d |  ƒ }  q Wx2 t j ƒ  D]$ } t | j d t | |  ƒ }  q< W|  S(   Ns   \1B\2s   \1%s\2(   t   _func2t   _func4t   _meth1t   func_ret   subt   _charst   keyst   meth_re(   t   fstrt   namet   char(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   fixtypecharsD   s
    "s   ([.]flat(\s*?[[=]))c         C` s  d | } d | } d | } d } t  j d | d | | f |  ƒ }  |  j | d | ƒ }  |  j | d | | f ƒ }  d } t | ƒ } t d | ƒ }	 xu t r|  j | | ƒ }
 |
 d k  rÆ Pn  |
 | } |  | d k ræ qž n  d	 |  |
  | |  | f }  | |	 | 7} qž W|  | f S(
   Ns	   import %ss   import %s as s   from %s import i    s   (import\s+[^,\n\r]+,\s*)(%s)s
   \1%s as %ss   import %s as %st   *s   %sfrom %s import %s(   t   reR    t   replacet   lent   Truet   find(   R$   R%   t   newnamet	   importstrt   importasstrt   fromstrt   fromallt   indt   Nlent   Nlen2t   found(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   changeimportsM   s*    


	
t   floatt   intt   complext	   ArrayTypet	   FloatTypet   IntTypet   ComplexTypes*   type\s*[(]([^)]*)[)]\s+(?:is|==)\s+(.*?%s)c         C` s+   x$ t  D] } t | j d |  ƒ }  q W|  S(   Ns   isinstance(\1, \2)(   t   _typest	   istest_reR    (   t   astrR%   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   fixistestingl   s    c         C` s”   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d	 d
 ƒ }  t j d |  ƒ } | j  d d ƒ } | j  d d ƒ }  |  S(   Ns   .typecode()s   .dtype.chars   .iscontiguous()s   .flags.contiguouss   .byteswapped()s   .byteswap()s   .toscalar()s   .item()s   .itemsize()s	   .itemsizes   @@@@\2s   .flats   .ravel()s   @@@@(   R*   t   flatindex_reR    (   RA   t   tmpstr(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   replaceattrq   s    s   ([^,(\s]+[.]spacesaver[(][)])s   (\S+[.]savespace[(].*[)])c         C` s(   t  j d |  ƒ }  t j d |  ƒ }  |  S(   NR,   s   pass  ## \1(   t   svspc2R    t   svspc3(   RA   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   replaceother‚   s    c         C` s1  |  } t  |  ƒ }  t |  ƒ }  t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d	 d
 ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } t |  d d ƒ \ }  } | p®| p®| } t |  ƒ }  t |  ƒ }  | |  k r't j j ƒ  j d ƒ } t	 j
 j t j d ƒ d } d  | | |  f }  |  d! f S|  d f S("   Nt   Numerics   numpy.oldnumerict
   multiarrayt   umatht	   Precisions   numpy.oldnumeric.precisiont	   UserArrays   numpy.oldnumeric.user_arrayt   ArrayPrinters   numpy.oldnumeric.array_printert   numerixt
   scipy_baset   Matrixs   numpy.oldnumeric.matrixt   MLabs   numpy.oldnumeric.mlabt   LinearAlgebras   numpy.oldnumeric.linear_algebrat   RNGs   numpy.oldnumeric.rngs   RNG.Statisticss   numpy.oldnumeric.rng_statst   RandomArrays   numpy.oldnumeric.random_arrayt   FFTs   numpy.oldnumeric.fftt   MAs   numpy.oldnumeric.mas	   %b %d, %Yi    iÿÿÿÿs:   ## Automatically adapted for numpy.oldnumeric %s by %s

%si   (   R'   RB   R7   RE   RH   t   datetimet   datet   todayt   strftimet   ost   patht   splitt   syst   argv(   t   filestrt   savestrt   fromall1t   fromall2t   fromall3R2   RZ   R%   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyR1   ‰   s:    
c         C` s*   t  |  d ƒ } | j | ƒ | j ƒ  d  S(   NR   (   t   filet   writet   close(   R%   Ra   t   fid(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   makenewfile¨   s    i   c         C` s�   t  |  ƒ } | j ƒ  } | j ƒ  t | ƒ \ } } | rŒ | ro t j j |  ƒ \ } } t j |  | d ƒ n t j |  ƒ t	 |  | ƒ 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
    s   .origN(
   t   opent   readRh   R1   R\   R]   t   splitextt   renamet   removeRj   (   t   filenamet   origRi   Ra   t   changedt   baset   ext(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyR   ­   s    
c         C` s   |  d } t  | ƒ d  S(   Ni   (   R   (   t   argsRp   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   fromargs¿   s    
c         C` sV   t  j  t j j |  d ƒ ƒ } x1 | D]) } | d d k rA q% n  t | | ƒ q% Wd S(   s  Convert all .py files to use numpy.oldnumeric (from Numeric) in the directory given

    For each changed 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   *.pyiøÿÿÿs   setup.pyN(   t   globR\   R]   t   joinR   (   t   direcRq   t   filest   afile(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyR   Ã   s
     s   (Numeric/arrayobject.h)c   
      C` s  | d k r- t j t j j |  d ƒ ƒ } n@ g  } x7 | D]/ } | j t j t j j |  d | ƒ ƒ ƒ q: Wx¦ | D]ž } t | ƒ } | j ƒ  } | j ƒ  t	 j
 d | ƒ \ } } | d k rt | rõ t j j | ƒ \ }	 } t j | |	 d ƒ n t j | ƒ t | | ƒ qt qt Wd S(   sª   Replace Numeric/arrayobject.h with numpy/oldnumeric.h in all files in the
    directory with extension give by list ext (if ext is None, then all files are
    replaced).R(   s   *.%ss   numpy/oldnumeric.hi    s   .origN(   t   NoneRw   R\   R]   Rx   t   extendRk   Rl   Rh   t	   header_ret   subnRm   Rn   Ro   Rj   (
   Ry   Rt   Rq   Rz   t   aextR{   Ri   R$   t   nRs   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyR   Ñ   s     !-
c         C` s0   t  | d d ƒt | d d d g d d ƒd  S(   NRq   i    Rt   R   t   c(   R   R   (   t   argt   dirnamet   fnames(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   _funcè   s    c         C` s   t  j j |  t d ƒ d S(   sB   Convert all .py files and source code files in the tree given
    N(   R\   R]   t   walkR†   R|   (   Ry   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyR   ì   s    t   __main__(/   t   __doc__t
   __future__R    R   R   t   __all__R_   R\   R)   Rw   R   R   R   R!   R   R#   R%   t   _astrt   compilet   DOTALLR"   R&   R'   RC   R7   R@   R?   RB   RE   RF   RG   RH   RX   R1   Rj   R   Rv   R]   t   curdirR   R~   R|   R   R†   R   t   __name__R`   (    (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code1.pyt   <module>   sf   	"



		
							