[R] Matrix efficiency in 1.9.0 vs 1.8.1
Stephen Ellner
spe2 at cornell.edu
Wed Apr 28 23:19:38 CEST 2004
I'm seeking some advice on effectively using the new Matrix
library in R1.9.0 for operations with large dense matrices. I'm working on
integral operator models (implemented numerically via matrix operations)
and except for the way entries are generated, the examples below really are
representative of my problem sizes.
My main concern is speed of large dense matrix multiplication.
In R 1.8.1 (Windows2000 Professional, dual AthlonMP 2800)
> a=matrix(rnorm(2500*2500),2500,2500); v=rnorm(2500);
> system.time(a%*%v);
[1] 0.11 0.00 0.12 NA NA
In R 1.9.0, same platform:
> a=matrix(rnorm(2500*2500),2500,2500); v=rnorm(2500);
> system.time(a%*%v);
[1] 0.24 0.00 0.25 NA NA
These differences are consistent. But using the Matrix library
in 1.9.0, the discrepancy disappears
> library(Matrix);
> a=Matrix(rnorm(2500*2500),2500,2500); v=Matrix(rnorm(2500),2500,1);
> system.time(a%*%v);
[1] 0.11 0.00 0.11 NA NA
The problem is
> b=a/3
Error in a/3 : non-numeric argument to binary operator
which seems to mean that I can't just rewrite code to use Matrix
instead of matrix objects -- I would have to do lots and lots of
conversions between Matrix and matrix. Am I missing a trick
here somewhere, that would let me use only Matrix objects and do
with them the things one can do with matrix objects? Or some other
way to avoid the twofold speed hit in moving to 1.9?
I've tried using the Rblas.dll for AthlonXP on CRAN, and
it doesn't help.
Thanks in advance,
Steve
Stephen P. Ellner (spe2 at cornell.edu)
Department of Ecology and Evolutionary Biology
Corson Hall, Cornell University, Ithaca NY 14853-2701
Phone (607) 254-4221 FAX (607) 255-8088
More information about the R-help
mailing list