From maechler at lynne.stat.math.ethz.ch  Tue May 12 14:33:48 2015
From: maechler at lynne.stat.math.ethz.ch (Martin Maechler)
Date: Tue, 12 May 2015 14:33:48 +0200
Subject: [Rd] Why is the diag function so slow (for extraction)?
In-Reply-To: <CAAVP=akUU10FPvkYhNBVQzi9jsMkCma-VVGgSqjGMpKF+G_4zA@mail.gmail.com>
References: <1430762350040-4706780.post@n4.nabble.com>
	<06F749E7-5096-438D-A299-667C7A77B477@gmail.com>
	<alpine.DEB.2.10.1505050844470.2460@luke-Latitude>
	<CAAVP=akUU10FPvkYhNBVQzi9jsMkCma-VVGgSqjGMpKF+G_4zA@mail.gmail.com>
Message-ID: <21841.62252.436947.835265@stat.math.ethz.ch>

>>>>> Steve Bronder <sbronder at stevebronder.com>
>>>>>     on Thu, 7 May 2015 11:49:49 -0400 writes:

    > Is it possible to replace c() with .subset()? 

It would be possible, but I think "entirely" wrong.

.subset() is documented to be an internal function not to be
used "lightly" and more to the point it is documented to *NOT*
dispatch at all.

If you read and understood what Peter and Luke wrote, you'd not
special case here:

diag() should not work only for pure matrices, but for all
"matrix-like" objects for which ``the usual methods'' work, such
as
   as.vector(.), c(.)

That's why there has been the c(.) in there.

You can always make code faster if you write the code so it only
has to work in one special case .. and work there very fast.


    > Example below
    > ####
    > ####

    > library(microbenchmark)



[Rd] Why is the diag function so slow (for extraction)?
Martin Maechler