ó Kc@sÿdZgZddlZejdƒddlZddlZddlZddlZd„Zd„Z d„Z d„Z ddl Z d„Z d „Zd „Zd „Zd „Zejjd „Zd„Zejjd„ZedkrûeejƒndS(sº This module converts code written for numpy.oldnumeric to work with numpy FIXME: Flesh this out. Makes the following changes: * Converts typecharacters '1swu' to 'bhHI' respectively when used as typecodes * Changes import statements * Change typecode= to dtype= * Eliminates savespace=xxx keyword arguments * Removes it when keyword is not given as well * replaces matrixmultiply with dot * converts functions that don't give axis= keyword that have changed * converts functions that don't give typecode= keyword that have changed * converts use of capitalized type-names * converts old function names in oldnumeric.linear_algebra, oldnumeric.random_array, and oldnumeric.fft iÿÿÿÿNs0numpy.oldnumeric.alter_code2 is not working yet.cCs^|jddƒ}|jddƒ}|jddƒ}|jddƒ}|jdd ƒ}|S( Ns's's'h's'b's'B's'1's'w's'H's'u's'I'(treplace(tastr((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pytreplacetypechars#s c Csód|}d|}d|}d}|j|d|ƒ}|j|d||fƒ}d}t|ƒ}td|ƒ} xn|j||ƒ} | dkrPn| |}||dkr½q{nd|| |||f}|| |7}q{||fS(Ns import %ss import %s as sfrom %s import isimport %s as %st*s%sfrom %s import %s(Rtlentfind( tfstrtnametnewnamet importstrt importasstrtfromstrtfromalltindtNlentNlen2tfound((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt changeimports+s&      cCs|jddƒ}|S(Ntmatrixmultiplytdot(R(R((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt replaceattrBscCs=tjdd|ƒ}|jddƒ}|jddƒ}|S(Ns typecode\s*=sdtype=t ArrayTypetndarraytNewAxistnewaxis(tretsubR(R((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt replaceotherFscCsNt|ddƒ\}}t|ddƒ\}}t|ddƒ\}}t|ddƒ\}}t|ddƒ\}}t|d d ƒ\}}t|d d ƒ\}}t|d dƒ\}}t|ddƒ\}}|pçtpç|}t|ƒ}t|ƒ}tjjƒjdƒ}tj j t j dƒd}d|||f}|S(Nsnumpy.oldnumerictnumpysnumpy.core.multiarraysnumpy.core.umatht LinearAlgebrasnumpy.linalg.oldtRNGsnumpy.random.oldrngsRNG.Statisticssnumpy.random.oldrngstatst RandomArraysnumpy.random.oldrandomarraytFFTs numpy.fft.oldtMAs numpy.core.mas %b %d, %Yiiÿÿÿÿs/## Automatically adapted for numpy %s by %s %s( Rtfromall2RRtdatetimetdatettodaytstrftimetostpathtsplittsystargv(tfilestrtfromall1tfromall3R R%R((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyR Ms$   cCs*t|dƒ}|j|ƒ|jƒdS(Ntw(tfiletwritetclose(RR,tfid((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt makenewfilebs cCsOt|ƒ}|jƒ}|jƒtjj|ƒ\}}t|d|ƒ|S(Ns.orig(R0treadR2R'R(tsplitextR4(RR3R,tbasetext((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt getandcopygs    cCs)t|ƒ}t|ƒ}t||ƒdS(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 N(R9R R4(tfilenameR,((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt convertfileos  cCs|d}t|ƒdS(Ni(R;(targsR:((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pytfromargsys cCs=tjtjj|dƒƒ}x|D]}t|ƒq%WdS(sòConvert all .py files to use NumPy (from Numeric) in the directory given For each file, a backup of .py is made as .py.orig. A new file named .py is then written with the updated code. s*.pyN(tglobR'R(tjoinR;(tdirectfilestafile((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt convertall}s cCst|ƒdS(N(RC(targtdirnametfnames((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt_funcˆscCstjj|tdƒdS(s-Convert all .py files in the tree given N(R'R(twalkRGtNone(R@((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt converttree‹st__main__(t__doc__t__all__twarningstwarnR*R'RR>RRRRR#R R4R9R;R=R(tcurdirRCRGRJt__name__R+(((s@/usr/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyts,