Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: Why is Mata much slower than MATLAB at matrix inversion?


From   "Joseph Coveney" <jcoveney@bigplanet.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Why is Mata much slower than MATLAB at matrix inversion?
Date   Fri, 20 Jul 2012 12:35:46 +0900

Patrick Roland wrote:

I'm comparing two code snippets. In Mata:

mata
timer_on(1)
M = rnormal(2000,2000,0,1)
J = cholinv(M)
timer_off(1)
timer()
end

In MATLAB:

tic;
M = normrnd(0,1,2000,2000);
J = inv(M);
toc;

I find that MATLAB is about 20 times faster (1.5 seconds vs 30
seconds). Is there something I'm missing here, or is MATLAB just much
faster at matrix inversion? I'd much prefer to use Mata because of
integration with Stata, but if the speed difference is going to be on
this order then MATLAB is more attractive.

Any input here is appreciated.

--------------------------------------------------------------------------------

Is -cholinv()- the Mata equivalent of MATLAB's inv()?  

Mata's -invsym()- is more than 100 times faster than its -cholinv()- on my
ancient laptop.

Joseph Coveney

. clear *

. set more off

. 
. mata:
------------------------------------------------- mata (type end to exit) ------
: M = rnormal(2000,2000,0,1)

: timer_on(1)

: J = cholinv(M)

: timer_off(1)

: 
: timer_on(2)

: J = invsym(M)

: timer_off(2)

: timer()

--------------------------------------------------------------------------------
timer report
  1.        116 /        1 =   116.227
  2.       .971 /        1 =      .971
--------------------------------------------------------------------------------

: 
: end
--------------------------------------------------------------------------------

. 
. exit

end of do-file




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index