[Rcpp-commits] r686 - pkg/inst/examples/FastLM
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 15 21:51:31 CET 2010
Author: edd
Date: 2010-02-15 21:51:31 +0100 (Mon, 15 Feb 2010)
New Revision: 686
Modified:
pkg/inst/examples/FastLM/fastLMviaArmadillo.r
pkg/inst/examples/FastLM/fastLMviaGSL.r
Log:
improved check functions
Modified: pkg/inst/examples/FastLM/fastLMviaArmadillo.r
===================================================================
--- pkg/inst/examples/FastLM/fastLMviaArmadillo.r 2010-02-15 20:31:06 UTC (rev 685)
+++ pkg/inst/examples/FastLM/fastLMviaArmadillo.r 2010-02-15 20:51:31 UTC (rev 686)
@@ -97,13 +97,12 @@
}
checkLmViaArmadillo <- function(y, X) {
- fun <- lmViaArmadillo();
- cat("Running lm via Armadillo\n")
+ fun <- lmViaArmadillo()
res <- fun(y, X)
- print(cbind(res[[1]], sqrt(diag(res[[2]]))))
- cat("Running lm()\n")
- print(summary(lm(y ~ X - 1)))
- invisible(NULL)
+ fit <- lm(y ~ X - 1)
+ rc <- all.equal( res[[1]], as.numeric(coef(fit))) &
+ all.equal( res[[2]], matrix(as.numeric(vcov(fit)),ncol=10,byrow=FALSE))
+ invisible(rc)
}
timeLmViaArmadillo <- function(y, X, N) {
@@ -121,6 +120,6 @@
N <- 100
-#checkLmViaArmadillo(y, X)
+stopifnot(checkLmViaArmadillo(y, X))
mt <- timeLmViaArmadillo(y, X, N)
cat("Armadillo: Running", N, "simulations yields (trimmed) mean time", mt, "\n")
Modified: pkg/inst/examples/FastLM/fastLMviaGSL.r
===================================================================
--- pkg/inst/examples/FastLM/fastLMviaGSL.r 2010-02-15 20:31:06 UTC (rev 685)
+++ pkg/inst/examples/FastLM/fastLMviaGSL.r 2010-02-15 20:51:31 UTC (rev 686)
@@ -92,13 +92,12 @@
}
checkLmViaGSL <- function(y, X) {
- fun <- lmViaGSL();
- cat("Running lm via GSL\n")
+ fun <- lmViaGSL()
res <- fun(y, X)
- print(cbind(res[[1]], sqrt(diag(res[[2]]))))
- cat("Running lm()\n")
- print(summary(lm(y ~ X - 1)))
- invisible(NULL)
+ fit <- lm(y ~ X - 1)
+ rc <- all.equal( res[[1]], as.numeric(coef(fit))) &
+ all.equal( res[[2]], matrix(as.numeric(vcov(fit)),ncol=10,byrow=FALSE))
+ invisible(rc)
}
timeLmViaGSL <- function(y, X, N) {
@@ -115,6 +114,6 @@
N <- 100
-#checkLmViaGSL(y, X)
+stopifnot(checkLmViaGSL(y, X))
mt <- timeLmViaGSL(y, X, N)
cat("GSL: Running", N, "simulations yields (trimmed) mean time", mt, "\n")
More information about the Rcpp-commits
mailing list