[R] Help with Matrix code optimization

Matt Shotwell Matt.Shotwell at Vanderbilt.Edu
Thu Feb 23 19:40:23 CET 2012


The chol and solve methods for dpoMatrix (Matrix package) are much
faster than the default methods. But, the time required to coerce a
regular matrix to dpoMatrix swamps the advantage.

Hence, I have the following problem, where use of dpoMatrix is worse
than a regular matrix.

library(Matrix)

x <- diag(10)

system.time(
  for(r in seq(0.1, 0.9, length.out=1000)) {
    m <- r^abs(row(x)-col(x));
    chol(m); solve(m);
  })

system.time(
  for(r in seq(0.1, 0.9, length.out=1000)) {
    M <- as(r^abs(row(x)-col(x)), 'dpoMatrix')
    chol(M); solve(M);
  })

Any ideas?



More information about the R-help mailing list