From pdalgd at gmail.com  Tue May  5 00:24:08 2015
From: pdalgd at gmail.com (peter dalgaard)
Date: Tue, 5 May 2015 00:24:08 +0200
Subject: [Rd] Why is the diag function so slow (for extraction)?
In-Reply-To: <1430762350040-4706780.post@n4.nabble.com>
References: <1430762350040-4706780.post@n4.nabble.com>
Message-ID: <06F749E7-5096-438D-A299-667C7A77B477@gmail.com>


> On 04 May 2015, at 19:59 , franknarf <by.hook.or at gmail.com> wrote:
> 
> But I'm still wondering why diag() uses c()...? With it being so slow, I'd
> be inclined to write a qdiag() without the c() and just use that the next
> time I need matrix algebra. Any insight would be appreciated; thanks!

Well, there are two possibilities: Either it is deliberate or it isn't. 

The latter isn't too unlikely, given that the effect is seen for large matrices. I would appear to be a matter of O(n) (picking out n items) vs. O(n^2) (copying an n x n matrix), but this might drown out in a context involving matrix multiplication and/or inversion, both of which are O(n^3). 

If it is deliberate, the question is why. There could be devils in the details; notice in particular that c() strips off non-name attributes. However, I'm not aware of a situation where such attributes could cause trouble.

-pd

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Why is the diag function so slow (for extraction)?
peter dalgaard