Interesting note: I updated my Python and Julia code to avoid double copying the slices from the arrays (I was copying R[i:i+1, :] twice, now I just do it once and reuse that copy). This decreased the Julia time to ~0.30 seconds (so cut about 0.08s) but didn't change the amount of time Python was taking (which I find to be quite odd, maybe numpy is somehow intelligent about not double copying for slices?).
Now Julia code takes 1.5x the amount of time as Python code. -Eric On Tuesday, December 24, 2013 4:17:16 PM UTC-6, Eric Martin wrote: > > Hi, > > I'm a new Julia user, and I decided to write a slightly optimized QR > decomposition for tridiagonal matrices (using Householder projections). > > My code (and it's output) is here: > https://gist.github.com/lightcatcher/8118181 . I've confirmed that both > implementations are correct (they match each other and the output from qr > and np.linalg.qr), but the Julia code consistently takes twice as long as > the Python code. > > From profiling the Julia code, I know that a very large part of the > runtime (> 90%) is spent doing the matrix multiplications to update > matrices R and Qt. I checked that my numpy installation is using LAPACK and > BLAS in /usr/lib (ie not using MKL), but I don't know how to check which > library Julia is using for matrix operations (but I assume its the same > one). > > Further interesting tidbits: > In Julia, using the built-in 'qr' takes ~.13s. > In Python, using np.linalg.qr takes ~.25s, so my Python tridiagonal QR > decomposition method is faster (as it takes ~0.2s). > > Also, its (marginally but consistently) faster in Julia to just call > "copy(T)" rather than "full(Tridiagonal(map(i -> diag(T, i), -1:1)...))", > which seems odd to me because "copy" should be O(N^2) and the other method > (only copying the sub, main, and super diagonals) is O(N), where N is the > dimension of a square matrix. > > > So, can anyone shed some light on why my Julia code is 2x as slow as the > very similar Python code? > Also, a tangential question: Does Julia have an equivalent to "if __name__ > == '__main__'"? (in other words how can I automatically run main). > > Thanks for the help, > Eric >
