[Rd] Why is the diag function so slow (for extraction)?
Radford Neal
radford at cs.toronto.edu
Wed May 13 19:31:17 CEST 2015
> 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
More information about the R-devel
mailing list