On 3/29/07, John Hunter <[EMAIL PROTECTED]> wrote: > On 3/28/07, Giorgio F. Gilestro <[EMAIL PROTECTED]> wrote: > > Hi, > > I have to question that will help some colleagues/friends of mine to switch > > to python from matlab. > > > > 1 - is there an automatic translator of code from matlab to > > python/numpy/matplotlib? I believe it would be very easy to implement due > > the similar syntax between the two. I could do something similar myself but > > first I better make sure it doesn't exist yet. > > None that I know of, and it probably wouldn't be easy. For one thing, > matlab uses parentheses for function calls and indexing, and it is > probably not always obvious which is which for a translator. One > could write something that got it mostly right and flagged > ambiguities, but I think you should expect that a human would have to > clean it up afterwards unless you attempt something ambitious and not > easy. Prove me wrong!
Another thing that is maybe even more problematic is that matlab uses call-by-value and value-based assignment while Python/Numpy uses call-by-reference and reference-based assignment. So in matlab A = B; A(3,2) = 22; will not modify B, but the equivalent numpy code A = B A[2,1] = 22 will modify both A and B. That means for a translator to create efficient code it really needs to analyze if each copy created is ever modified, and if so whether that matters. So I think you'd need to do a full parsing of the matlab code. No regexp tricks are going to cut it. Another very tricky thing is that the indexing rules are very different. Any time you see something like A(idx) in matlab you have to really know what type of thing idx is exactly in order to translate it properly. And then there's the issue with matlab code that calls "SomeNonTrivialToolboxRoutine(x)". Even if it does exist in SciPy, often the parameters are very different. And there's the one-based vs zero-based thing. But that's probably the least of one's worries. So there are a lot of challenges. But none of it seems impossible, and there are some shortcuts you could take to get something that would still be a useful first-pass, but require hand touch-up. On the plus side, it's probably easier to translate from a pass-by-value language to pass-by-reference than the other way around. --bb ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users