Current File : //usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyo
�
E�`Qc@s�dZddddgZddlZddlZddlZddlZd�Zejd�Zd	�Z	d
�Z
ejd�Zejd�Zejd
�Z
ejd�Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�Zejd�Zd�ZddlZd�Zd�Zdd�Zd�Zejjdd�Zejd�Z ejjddd�Z"d �Z#ejjd!�Z$e%d"kr�e$ej&�ndS(#s6
This module converts code written for numarray to run with numpy

Makes the following changes:
 * Changes import statements

   import numarray.package
       --> import numpy.numarray.package as numarray_package
           with all numarray.package in code changed to numarray_package

   import numarray --> import numpy.numarray as numarray
   import numarray.package as <yyy> --> import numpy.numarray.package as <yyy>

   from numarray import <xxx> --> from numpy.numarray import <xxx>
   from numarray.package import <xxx>
       --> from numpy.numarray.package import <xxx>

   package can be convolve, image, nd_image, mlab, linear_algebra, ma,
                  matrix, fft, random_array


 * Makes search and replace changes to:
   - .imaginary --> .imag
   - .flat --> .ravel() (most of the time)
   - .byteswapped() --> .byteswap(False)
   - .byteswap() --> .byteswap(True)
   - .info() --> numarray.info(self)
   - .isaligned() --> .flags.aligned
   - .isbyteswapped() --> (not .dtype.isnative)
   - .typecode() --> .dtype.char
   - .iscontiguous() --> .flags.contiguous
   - .is_c_array() --> .flags.carray and .dtype.isnative
   - .is_fortran_contiguous() --> .flags.fortran
   - .is_f_array() --> .dtype.isnative and .flags.farray
   - .itemsize() --> .itemsize
   - .nelements() --> .size
   - self.new(type) --> numarray.newobj(self, type)
   - .repeat(r) --> .repeat(r, axis=0)
   - .size() --> .size
   - self.type() -- numarray.typefrom(self)
   - .typecode() --> .dtype.char
   - .stddev() --> .std()
   - .togglebyteorder() --> numarray.togglebyteorder(self)
   - .getshape() --> .shape
   - .setshape(obj) --> .shape=obj
   - .getflat() --> .ravel()
   - .getreal() --> .real
   - .setreal() --> .real =
   - .getimag() --> .imag
   - .setimag() --> .imag =
   - .getimaginary() --> .imag
   - .setimaginary() --> .imag

tconvertfilet
convertalltconverttreet
convertsrci����NcCs^d|}d|}d|}d}|}d|krK|jdd�}ntjd|d||f|�}|j|d|�}|j|d	||f�}||kr�|j||�}nd}t|�}	td|�}
xn|j||�}|dkrPn||	}||d
kr(q�nd|| |||f}||
|	7}q�||fS(Ns	import %ss
import %s as sfrom %s import it.t_s(import\s+[^,\n\r]+,\s*)(%s)s
\1%s as %ssimport %s as %st*s%sfrom %s import %s(treplacetretsubtlentfind(tfstrtnametnewnamet	importstrtimportasstrtfromstrtfromalltname_tindtNlentNlen2tfound((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyt
changeimports>s4




s([.]flat(\s*?[[=]))cCsL|jd�}|jtjd|�}d|| tjd||f}|S(Ntimportis%s%s%s%ss!import numpy.numarray as numarray(Rtrfindtostlinesep(tastrRtstart((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyt	addimport`scCsZ|jdd�}|jdd�}|jdd�}|jdd�}|jd	d
�}|jdd�}|jd
d�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}tjd|�}|jdd�}|jd d�}|S(!Ns
.imaginarys.imags.byteswapped()s.byteswap(False)s.byteswap()s.byteswap(True)s.isaligned()s.flags.aligneds.iscontiguous()s.flags.contiguouss.is_fortran_contiguous()s.flags.fortrans.itemsize()s	.itemsizes.size()s.sizes.nelements()s.typecode()s.dtype.chars	.stddev()s.std()s.getshape()s.shapes
.getflat()s.ravel()s.getreals.reals.getimags
.getimaginarys@@@@\2s.flats@@@@(Rtflatindex_reR	(Rttmpstr((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pytreplaceattris(s(\S+)\s*[.]\s*info\s*[(]\s*[)]s%(\S+)\s*[.]\s*new\s*[(]\s*(\S+)\s*[)]s)(\S+)\s*[.]\s*togglebyteorder\s*[(]\s*[)]s(\S+)\s*[.]\s*type\s*[(]\s*[)]s'(\S+)\s*[.]\s*isbyteswapped\s*[(]\s*[)]s$(\S+)\s*[.]\s*is_c_array\s*[(]\s*[)]s$(\S+)\s*[.]\s*is_f_array\s*[(]\s*[)]s((\S+)\s*[.]\s*repeat\s*[(]\s*(\S+)\s*[)]s*(\S+)\s*[.]\s*setshape\s*[(]\s*(\S+)\s*[)]s)(\S+)\s*[.]\s*setreal\s*[(]\s*(\S+)\s*[)]s)(\S+)\s*[.]\s*setimag\s*[(]\s*(\S+)\s*[)]s.(\S+)\s*[.]\s*setimaginary\s*[(]\s*(\S+)\s*[)]cCstjd|�\}}tjd|�\}}tjd|�\}}tjd|�\}}||||dkr�t|�}ntjd|�}tjd|�}t	jd|�}t
jd	|�}tjd
|�}tjd|�}t
jd|�}tjd|�}|S(
Nsnumarray.info(\1)snumarray.newobj(\1, \2)snumarray.togglebyteorder(\1)snumarray.typefrom(\1)isnot \1.dtype.isnatives%\1.dtype.isnative and \1.flags.carrays%\1.dtype.isnative and \1.flags.farrays\1.repeat(\2, axis=0)s
\1.shape = \2s\1.real = \2s\1.imag = \2(tinfo_retsubntnew_ret	toggle_rettype_reRt	isbyte_reR	t	iscarr_ret	isfarr_ret	repeat_retsetshape_ret
setreal_ret
setimag_retsetimaginary_re(Rtn1tn2tn3tn4((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pytreplaceother�sc
Cs|}t|dd�\}}d}d}xeddddddd	d
ddg
D]?}|dkrod
|}nt|||||�\}}qPWt|�}t|�}||kr	tjjtjd�d}tj	j
�jd�}d|||f}|dfS|dfS(Ntnumarraysnumpy.numarrayttconvolvetimagetnd_imagetmlabtlinear_algebratmatmatrixtffttrandom_arrayRii����s	%b %d, %Ys8## Automatically adapted for numpy.numarray %s by %s

%si(RR"R4Rtpathtsplittsystargvtdatetimetdatettodaytstrftime(tfilestrtsavestrRtbasetnewbaseR	R
RF((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyR�s$
$
cCs*t|d�}|j|�|j�dS(Ntw(tfiletwritetclose(R
RHtfid((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pytmakenewfile�s
icCs�t|�}|j�}|j�t|�\}}|r�|rotjj|�\}}tj||d�n
tj|�t	||�ndS(s�Convert the filename given from using Numarray to using NumPy

    Copies the file to filename.orig and then over-writes the file
    with the updated code
    s.origN(
topentreadRORRR@tsplitexttrenametremoveRQ(tfilenametorigRPRHtchangedRJtext((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyR�s

cCs|d}t|�dS(Ni(R(targsRW((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pytfromargs�s
cCsVtjtjj|d��}x1|D])}|ddkrAq%nt||�q%WdS(s�Convert all .py files to use numpy.oldnumeric (from Numeric) 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*.pyi����ssetup.pyN(tglobRR@tjoinR(tdirecRXtfilestafile((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyR�s

s(numarray/libnumarray.h)c
Cs|dkr-tjtjj|d��}n@g}x7|D]/}|jtjtjj|d|���q:Wx�|D]�}t|�}|j�}|j�t	j
d|�\}}|dkrt|r�tjj|�\}	}tj||	d�n
tj
|�t||�qtqtWdS(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).Rs*.%ssnumpy/libnumarray.his.origN(tNoneR]RR@R^textendRRRSROt	header_reR$RTRURVRQ(
R_RZRXR`taextRaRPRtnRJ((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyR�s !
-


cCs-t|dd�t|ddgdd�dS(NRXithtc(RR(targtdirnametfnames((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyt_func�scCstjj|td�dS(s-Convert all .py files in the tree given

    N(RR@twalkRlRb(R_((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyRst__main__('t__doc__t__all__RBRRR]RtcompileR RR"R#R%R&R'R(R)R*R+R,R-R.R/R4RDRRQRR\R@tcurdirRRdRbRRlRt__name__RC(((s@/usr/lib64/python2.7/site-packages/numpy/numarray/alter_code1.pyt<module>6sD