From radford at cs.toronto.edu  Wed May 13 19:31:17 2015
From: radford at cs.toronto.edu (Radford Neal)
Date: Wed, 13 May 2015 13:31:17 -0400
Subject: [Rd] Why is the diag function so slow (for extraction)?
In-Reply-To: <mailman.21.1431511203.5843.r-devel@r-project.org>
References: <mailman.21.1431511203.5843.r-devel@r-project.org>
Message-ID: <20150513173117.GA31260@cs.toronto.edu>

> From: Martin Maechler <maechler at lynne.stat.math.ethz.ch>

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

help(diag) gives no hint whatever that diag(x) will work for
objects that are "matrix-like", but aren't actual matrices.

help(c) explicitly says that methods for it are NOT required to
convert matrices to vectors.

So you're advocating slowing down all ordinary uses of diag to
accommodate a usage that nobody thought was important enough to
actually document.

   Radford Neal



[Rd] Why is the diag function so slow (for extraction)?
Radford Neal