From help-request at octave dot org Wed Mar 22 10:39:35 2006 Subject: Re: octave loop slowness (was "") From: Przemek Klosowski To: help at octave dot org Date: Wed, 22 Mar 2006 11:37:17 -0500 (EST) True, there is no requirement that you generate Java bytecode to be fed to a JVM to get JIT; however, I am extremely leery of reinventing the wheel. Especially when the wheel in question is a very very hairy piece of software. "When all you have is a hammer, everything looks like a nail" The problem with JVM is that the bytecodes that it defines are designed for a general purpose interpreter. Octave needs bytecodes that would perform octavish operations, such as matrix transpose, multiplication, etc. If the bytecode execution loop crawled through the data objects element by element, the performance would suck. Whatever is used for Octave has to have primitives for dealing with high-level objects like entire matrices---I don't know if JVM can be jiggered to do that; maybe it could, by some combination of native methods and binary opaque object data types, but I somehow doubt it. In the end, I can't muster empathy for low loop speed problems. As was said here before, if the program is slow because of loops, it is probably needs rethinking. Someone else complained that Octave forces people to do unnatural operations instead of 'simple loops'. I think they got it precisely backwards!!! It is the entire point of matrix-based systems like Octave that you get to write them in a vectorized fashion; they are only 'unnatural' because we didn't learn math through linear algebra, because there were no systems like Octave. My favorite example of that is the Savitzky-Golay filter code that I needed in my work 15 years ago or so. The traditional 'Fortran' loopy code for it takes about a page of loops: http://www.library.cornell.edu/nr/bookcpdf/c14-8.pdf I set out to rewrite it in Octave, and at first it was frustrating, but when I thought about it, it opened my eyes to a different way of working and I loved Octave from that moment on. In vector notation, that whole page is simply lc = (l-1)/2; X = [-lc:lc]' * ones(1,forder + 1); p = ones(l,1) * [0:forder]; X = X .^ p; F = pinv(X); which actually corresponds better to the actual math definition of the filter (eq. (14.8.6) in the book above), and it could be written in two lines if the variables weren't broken out into separate lines for clarity. p ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------