From luke-tierney at uiowa.edu  Tue May  5 15:46:45 2015
From: luke-tierney at uiowa.edu (luke-tierney at uiowa.edu)
Date: Tue, 5 May 2015 08:46:45 -0500
Subject: [Rd] Why is the diag function so slow (for extraction)?
In-Reply-To: <06F749E7-5096-438D-A299-667C7A77B477@gmail.com>
References: <1430762350040-4706780.post@n4.nabble.com>
	<06F749E7-5096-438D-A299-667C7A77B477@gmail.com>
Message-ID: <alpine.DEB.2.10.1505050844470.2460@luke-Latitude>

Looks like the c(x)[...] bit used to be as.matrix(x)[...]. Not sure
why the change was made many years ago, but this was before names were
handled explicitly. It would definitely be better to not force the
duplicate, at least in the case where we are sure c() and [ would not
dispatch.

Best,

luke

On Mon, 4 May 2015, peter dalgaard wrote:

>
>> 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
>
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



[Rd] Why is the diag function so slow (for extraction)?
luke-tierney at uiowa.edu