3 # A faster lm() replacement based on GNU GSL
5 # This first appeared in the 'Intro to HPC tutorials'
6 # but has been wrapped in inline::cfunction() here
8 # Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
10 # This file is part of Rcpp.
12 # Rcpp is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 2 of the License, or
15 # (at your option) any later version.
17 # Rcpp is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
27 checkLmGSL <- function(y, X) {
31 rc <- all.equal( res[[1]], as.numeric(coef(fit))) &
32 all.equal( res[[2]], as.numeric(coef(summary(fit))[,2]))
36 timeLmGSL <- function(y, X, N) {
38 meantime <- mean(replicate(N, system.time(fun(y, X))["elapsed"]), trim=0.05)
44 X <- cbind( rep(1,n), matrix(rnorm(n*k), ncol=k) )
46 y <- as.numeric(X %*% truecoef + rnorm(n))
50 stopifnot(checkLmGSL(y, X))
51 mt <- timeLmGSL(y, X, N)
52 cat("GSL: Running", N, "simulations yields (trimmed) mean time", mt, "\n")