Is there strong interest in automating matlab to numpy conversion?
I have a working version of a matlab to python translator. It allows translation of matlab scripts into numpy constructs, supporting most of the matlab language. The parser is nearly complete. Most of the remaining work involves providing a robust translation. Such as * making sure that copies on assign are done when needed. * correct indexing a(:) becomes a.flatten(1) when on the left hand side (lhs) of equals and a[:] when on the right hand side I've seen a few projects attempt to do this, but for one reason or another have stopped it. _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
On Sat, Jan 31, 2009 at 19:06, Eric Schug <[hidden email]> wrote:
> Is there strong interest in automating matlab to numpy conversion? Yes! Please post your code somewhere! -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
On 31-Jan-09, at 8:06 PM, Eric Schug wrote:
> Is there strong interest in automating matlab to numpy conversion? I think there is a strong interest in this. One of the main obstacles to changing environments is inertia and familiarity. My advisor repeatedly expresses his wish to give Python another try, and having an easy way to show him how his existing scripts translate would be awesome. Of course there are caveats, corner cases where such translations will fail, but a fairly foolproof method of converting simple scripts would be just fantastic. I imagine if you've gotten further along than previous attempts you'll receive a lot of street cred on this list and probably a lot of patches to make things work better. :) David _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Robert Kern-2
>> Is there strong interest in automating matlab to numpy conversion? > Yes! Please post your code somewhere! seconded !!!!! I'm currently working on a grant that has turned out to involve porting a lot of matlab code to python; you will be gratefully acknowledged in whatever comes of the work of the grant. -- KY _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
I am interested with this project, too. Would be much better to have
an automated tool than doing manual conversations. Just for your information, there is a IDL-to-Python conversation tool named i2py @ http://code.google.com/p/i2py/ On Jan 31, 7:06 pm, Eric Schug <[hidden email]> wrote: > Is there strong interest in automating matlab to numpy conversion? > > I have a working version of a matlab to python translator. > It allows translation of matlab scripts into numpy constructs, > supporting most of the matlab language. The parser is nearly complete. > Most of the remaining work involves providing a robust translation. Such as > * making sure that copies on assign are done when needed. > * correct indexing a(:) becomes a.flatten(1) when on the left hand > side (lhs) of equals > and a[:] when on the right hand side > > I've seen a few projects attempt to do this, but for one reason or > another have stopped it. > > _______________________________________________ > SciPy-user mailing list > [hidden email]://projects.scipy.org/mailman/listinfo/scipy-user SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Robert Kern-2
Robert Kern wrote: > On Sat, Jan 31, 2009 at 19:06, Eric Schug <[hidden email]> wrote: > >> Is there strong interest in automating matlab to numpy conversion? >> > > Yes! Please post your code somewhere! > > +1 And this is a very good moment for the persons who are creating a Matlab like environment, including the Matlab-like workspace, to show there creations. cheers, Stef _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
+1
On Sun, Feb 1, 2009 at 5:29 PM, <[hidden email]> wrote: Send SciPy-user mailing list submissions to -- Alex Liberzon Turbulence Structure Laboratory (http://www.eng.tau.ac.il/efdl) School of Mechanical Engineering Tel Aviv University Tel: +972-3-640-8928 (office) Tel: +972-3-640-6860 (lab) E-mail: [hidden email] _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Robert Kern-2
> On Sat, Jan 31, 2009 at 19:06, Eric Schug <[hidden email]> wrote:
>> Is there strong interest in automating matlab to numpy conversion? > > Yes! Please post your code somewhere! For those who are interested, there are two ways of doing this: The most portable is to call the 'Matlab engine', which is a C and Fortran library for automating Matlab. This can be done using f2py or ctypes (wrap libeng.dll and libmx.dll). http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_external/f29148.html&http://www.google.no/search?rlz=1C1GGLS_noNO291NO303&aq=f&sourceid=chrome&ie=UTF-8&q=matlab+engine The other option (Windows only) is to use Matlab as an outproc COM server. This will require pywin32. S.M. _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
Sturla Molden wrote:
> > For those who are interested, there are two ways of doing this: > I think Eric talked about source code translation, that is .m to .py. > The most portable is to call the 'Matlab engine', which is a C and Fortran > library for automating Matlab. This can be done using f2py or ctypes (wrap > libeng.dll and libmx.dll). > If you are not aware of it, there is already code for it: http://svn.scipy.org/svn/scikits/trunk/mlabwrap/ cheers, David _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
I just came across this, which looks very relevant.
http://frontiersin.org/neuroinformatics/paper/10.3389/neuro.11/005.2009/ David Cournapeau wrote: > Sturla Molden wrote: >> For those who are interested, there are two ways of doing this: >> > > I think Eric talked about source code translation, that is .m to .py. > >> The most portable is to call the 'Matlab engine', which is a C and Fortran >> library for automating Matlab. This can be done using f2py or ctypes (wrap >> libeng.dll and libmx.dll). >> > > If you are not aware of it, there is already code for it: > > http://svn.scipy.org/svn/scikits/trunk/mlabwrap/ > > cheers, > > David > _______________________________________________ > SciPy-user mailing list > [hidden email] > http://projects.scipy.org/mailman/listinfo/scipy-user _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
Eric Schug wrote:
> Is there strong interest in automating matlab to numpy conversion? > > I have a working version of a matlab to python translator. > It allows translation of matlab scripts into numpy constructs, > supporting most of the matlab language. The parser is nearly > complete. Most of the remaining work involves providing a robust > translation. Such as > * making sure that copies on assign are done when needed. > * correct indexing a(:) becomes a.flatten(1) when on the left hand > side (lhs) of equals > and a[:] when on the right hand side > > > I've seen a few projects attempt to do this, but for one reason or > another have stopped it. > > http://sourceforge.net/projects/libermate/ Latest version now supports simple command expressions (e.g hold on) _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
Thank you Eric,
it's very interesting, certainly it should be mentioned in scipy.org topical software section, also, I guess, it's worth mention in such mail lists as http://groups.google.com/group/comp.soft-sys.matlab, http://groups.google.com/group/comp.lang.python.announce, http://groups.google.com/group/sci.op-research, http://groups.google.com/group/sci.math.num-analysis Regards, Dmitrey Eric Schug wrote: > Eric Schug wrote: > > For those interested, my new project has been uploaded sourceforge at, > http://sourceforge.net/projects/libermate/ > > Latest version now supports simple command expressions (e.g hold on) > > _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
On Sat, 21 Feb 2009 11:38:50 -0500
Eric Schug <[hidden email]> wrote: > Eric Schug wrote: >> Is there strong interest in automating matlab to numpy >>conversion? >> >> I have a working version of a matlab to python >>translator. >> It allows translation of matlab scripts into numpy >>constructs, >> supporting most of the matlab language. The parser is >>nearly >> complete. Most of the remaining work involves providing >>a robust >> translation. Such as >> * making sure that copies on assign are done when >>needed. >> * correct indexing a(:) becomes a.flatten(1) when on >>the left hand >> side (lhs) of equals >> and a[:] when on the right hand side >> >> >> I've seen a few projects attempt to do this, but for one >>reason or >> another have stopped it. >> >> >For those interested, my new project has been uploaded >sourceforge at, > http://sourceforge.net/projects/libermate/ > > Latest version now supports simple command expressions >(e.g hold on) > > > > _______________________________________________ > SciPy-user mailing list > [hidden email] > http://projects.scipy.org/mailman/listinfo/scipy-user Hi Eric, You might be interested in some tests. Different Matlab Toolboxes are available through http://www.maths.manchester.ac.uk/~higham/mg/ Cheers, Nils _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
You may be all interested in
http://ompc.juricap.com/ it seems very promising too. tiziano On Sat 21 Feb, 18:39, Nils Wagner wrote: > On Sat, 21 Feb 2009 11:38:50 -0500 > Eric Schug <[hidden email]> wrote: > > Eric Schug wrote: > >> Is there strong interest in automating matlab to numpy > >>conversion? > >> > >> I have a working version of a matlab to python > >>translator. > >> It allows translation of matlab scripts into numpy > >>constructs, > >> supporting most of the matlab language. The parser is > >>nearly > >> complete. Most of the remaining work involves providing > >>a robust > >> translation. Such as > >> * making sure that copies on assign are done when > >>needed. > >> * correct indexing a(:) becomes a.flatten(1) when on > >>the left hand > >> side (lhs) of equals > >> and a[:] when on the right hand side > >> > >> > >> I've seen a few projects attempt to do this, but for one > >>reason or > >> another have stopped it. > >> > >> > >For those interested, my new project has been uploaded > >sourceforge at, > > http://sourceforge.net/projects/libermate/ > > > > Latest version now supports simple command expressions > >(e.g hold on) > > > > > > > > _______________________________________________ > > SciPy-user mailing list > > [hidden email] > > http://projects.scipy.org/mailman/listinfo/scipy-user > > Hi Eric, > > You might be interested in some tests. > > Different Matlab Toolboxes are available through > > http://www.maths.manchester.ac.uk/~higham/mg/ > > Cheers, > > Nils > > _______________________________________________ > SciPy-user mailing list > [hidden email] > http://projects.scipy.org/mailman/listinfo/scipy-user SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
hi Eric,
I'm trying to use your soft on a file from matlab fileexchage area (BTW you could place a link to your soft there), so it prints The following appear to be variables: status, A, b, lb, val, f, M, bound, options, Aeq, val0, x, x0, beq, e, ub The following appear to be functions: rec, inf, IP1, linprog, optimset So I would say "inf" is certainly not a function, it's equivalent to numpy.inf (I guess you know). BTW I think it would be a good idea to mention your software in http://www.scipy.org/NumPy_for_Matlab_Users as well as in Octave, SAGE mail lists. Regards, D. Eric Schug wrote: > For those interested, my new project has been uploaded sourceforge at, > http://sourceforge.net/projects/libermate/ > > Latest version now supports simple command expressions (e.g hold on) > > > > _______________________________________________ > SciPy-user mailing list > [hidden email] > http://projects.scipy.org/mailman/listinfo/scipy-user > > > > _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
> Eric Schug wrote:
>> For those interested, my new project has been uploaded sourceforge at, >> http://sourceforge.net/projects/libermate/ >> >> Latest version now supports simple command expressions (e.g hold on) >> I tried it out on some simple matlab files. I didn't try to run the translated files yet, but two translations make the code less readable * translation of integers to floats, e.g. for array indices or for arange * multiplication of scalar with array is translated with dot, eg m: randn(n,k-1)*10 -> py: = dot(randn(n, k-1.), 10.) string array in matlab came out as empty numpy array m: vnames=['yvar', 'iota', 'x1 ', 'x2 ']; -> py: vnames = array(r_[]) Importing everything is a source of possible errors (e.g. pylab overwrites numpy names) from numpy import * import scipy # if available import pylab (from matlibplot) try: from pylab import * except ImportError: pass I would prefer the current standard import numpy as np import matplotlib.pylab as plt and keep the name space as part of the name, e.g. np.dot, np.exp, ... But it looks like it will save a lot of typing and editing, even though it will need careful proof reading. Thanks, Josef _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
[hidden email] wrote:
>> Eric Schug wrote: >> >>> For those interested, my new project has been uploaded sourceforge at, >>> http://sourceforge.net/projects/libermate/ >>> >>> Latest version now supports simple command expressions (e.g hold on) >>> >>> > > > from numpy import * > import scipy > > I would prefer the current standard > import numpy as np > and keep the name space as part of the name, e.g. np.dot, np.exp, ... > +1 Let me add some more cents: instead of round(arr) it should be used arr.round() (because Python's round doesn't work for numpy arrays) zeros(m,n) should be zeros((m,n)) ones(m,n) should be ones((m,n)) "end" should go to "-1" (now "xend-1") variables of index type (for example, obtained from ind=find(...) replaced by ind=nonzero() or ind=where()) should not be decreased in the following lines with indexing, eg arr[ind] should be used instead of arr[ind-1] for A=[B C ...] and A=[B;C] using A=hstack((B, C,...)) and A=vstack((B, C,...)) is more readable and natural than current array(r_[c_[B], c_[C]]) Regards, D. _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
Thanks everyone for you comments.
I will try to address them. > * translation of integers to floats, e.g. for array indices or for arange > Rational for cast if int to float. Matlab always uses float data type, for most expressions e.g. try format long e a=1 This is mostly a problem for division, integer division would be used in some cases yielding the wrong results. e.g. a=1/2 would give 0 and not 0.5 as it does in Matlab. An alternative method would be to use from __future__ import division I think the best would be to have this be a command line option, so that various translation rules could be enabled or disabled. > * multiplication of scalar with array is translated with dot, eg > m: randn(n,k-1)*10 -> py: = dot(randn(n, k-1.), 10.) Matrix multiplication in matlab is * -> dot in Numpy but with scalars should use more readable * > string array in matlab came out as empty numpy array > > m: > vnames=['yvar', > 'iota', > 'x1 ', > 'x2 ']; > -> py: > vnames = array(r_[]) > Importing everything is a source of possible errors (e.g. pylab > overwrites numpy names) > > from numpy import * > import scipy > # if available import pylab (from matlibplot) > try: > from pylab import * > except ImportError: > pass need to cross reference numpy functions. I've added the rest to tracker at SourceForge. Although, still learning to use Source forge tools. Eric. _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
In reply to this post by Eric Schug
hi Eric,
Eric Schug wrote: > Eric Schug wrote: > >> Is there strong interest in automating matlab to numpy conversion? >> >> I have a working version of a matlab to python translator. >> It allows translation of matlab scripts into numpy constructs, >> supporting most of the matlab language. The parser is nearly >> complete. Most of the remaining work involves providing a robust >> translation. Such as >> * making sure that copies on assign are done when needed. >> * correct indexing a(:) becomes a.flatten(1) when on the left hand >> side (lhs) of equals >> and a[:] when on the right hand side >> >> >> I've seen a few projects attempt to do this, but for one reason or >> another have stopped it. >> >> >> > > attached the m-file and the hand-corrected py-file (where you can changes the corrections). These are our findings * show() command is not needed in Matlab. * Case-Senitive function calls are automatically translated in Matlab * Complex number i is transformed in a function 1j() * product of 2 numbers is changed in a (ugly) dot-product. * can't handle unicode e.g. "reëel" * matdiv is not found * graphs are nicer, but axis are uglier * subplot needs integer values the resulting graphs from both Matlab and Python, can be seen here (we might not have used the latest MatPlotLib). good luck and cheers, Stef w = linspace(1,4000,1000) tau = 1e-3 H = tau*i*w ./ ( 1 + tau*i*w ) re = real(H) im = imag(H) ampl = abs(H) fase = angle(H) / (2*pi) * 360 v = [re',im',ampl',fase'] subplot(221) plot(w,re) xlabel('w in rad/s') YLABEL('reeele deel') subplot(222) plot(w,im) xlabel('w in rad/s') YLABEL('imaginaire deel') subplot(223) plot(w,ampl) YLABEL('amplitude') xlabel('w in rad/s') subplot(224) plot(w,fase) YLABEL('fase verschil in graden') xlabel('w in rad/s') from numpy import * import scipy # if available import pylab (from matlibplot) try: from pylab import * except ImportError: pass w = linspace(1., 4000., 1000.) tau = 1e-3 #H = (dot(dot(tau, 1j()), w)/(1.+dot(dot(tau, 1j()), w))) H = (dot(dot(tau, 1j), w)/(1.+dot(dot(tau, 1j), w))) re = real(H) im = imag(H) ampl = abs(H) #fase = dot(matdiv(angle(H), dot(2., pi)), 360.) fase = dot((angle(H) / dot(2., pi)), 360.) v = array(c_[re.conj().T, im.conj().T, ampl.conj().T, fase.conj().T]) #subplot(221.) subplot(221) plot(w, re) xlabel('w in rad/s') #YLABEL('reeele deel') ylabel('reeele deel') #subplot(222.) subplot(222) plot(w, im) xlabel('w in rad/s') #YLABEL('imaginaire deel') ylabel('imaginaire deel') #subplot(223.) subplot(223) plot(w, ampl) #YLABEL('amplitude') ylabel('amplitude') xlabel('w in rad/s') #subplot(224.) subplot(224) plot(w, fase) #YLABEL('fase verschil in graden') ylabel('fase verschil in graden') xlabel('w in rad/s') show() #<<<<< Not in Matlab _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
forgot the link
> > > the resulting graphs from both Matlab and Python, can be seen here > (we might not have used the latest MatPlotLib). > http://mientki.ruhosting.nl/data_www/pylab_works/matlab.html _______________________________________________ SciPy-user mailing list [hidden email] http://projects.scipy.org/mailman/listinfo/scipy-user |
Free forum by Nabble | Edit this page |