[Vegan-commits] r1836 - in pkg/vegan: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Sep 11 08:01:38 CEST 2011


Author: jarioksa
Date: 2011-09-11 08:01:29 +0200 (Sun, 11 Sep 2011)
New Revision: 1836

Modified:
   pkg/vegan/R/summary.permat.R
   pkg/vegan/inst/ChangeLog
Log:
HUGE speed-up in running example(permatfull) by making summary.permat much faster

Modified: pkg/vegan/R/summary.permat.R
===================================================================
--- pkg/vegan/R/summary.permat.R	2011-09-10 14:17:59 UTC (rev 1835)
+++ pkg/vegan/R/summary.permat.R	2011-09-11 06:01:29 UTC (rev 1836)
@@ -3,6 +3,8 @@
     function(object, ...)
 {
     x <- object
+    ## calculations are much faster if x$orig is matrix instead of data.frame
+    x$orig <- data.matrix(x$orig)
     n <- attr(x, "times")
     ss <- sum(x$orig)
     fi <- sum(x$orig > 0)

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-09-10 14:17:59 UTC (rev 1835)
+++ pkg/vegan/inst/ChangeLog	2011-09-11 06:01:29 UTC (rev 1836)
@@ -18,6 +18,30 @@
 	spent in C, and the new permatswap/permatswap1 spends 2.2x longer
 	in other parts. With faster C code the net slowdown is 1.7x.
 
+	* permatfull, permatswap summary: huge speed-up. Running
+	example(permatfull) was by far the slowest part of R CMD check: it
+	took more than 21% of the example checking time. Especially
+	plot.permat() and as.ts.permat() were extremely slow. I traced
+	this to summary.permat, and there in calculating Bray-Curtis
+	dissimilarities. Here the original data x$orig was a data.frame,
+	and changing this to matrix made a huge difference. Here timings
+	in my MacBook Air 1.6 GHz:
+
+	> system.time(bray <- sapply(x$perm, function(z) 
+	      sum(abs(x$orig - z)) / sum(x$orig + z)))
+        user  system elapsed 
+        3.609   0.046   3.662 
+        Change x$orig to a matrix:
+        > system.time(bray <- sapply(x$perm, function(z) 
+	        sum(abs(x$orig - z)) / sum(x$orig + z)))
+        user  system elapsed 
+        0.007   0.000   0.007
+
+	After changing x$orig to matrix in summary.permat, the
+	example(permutest) used only 5% of total example checking time,
+	the whole vegan example checking time was reduced by 13%, and
+	permatfull checks run 4.5x faster.
+
 	* New functions: permatfull1 and permatswap1. Both functions
 	return a single permuted matrix. These functions are now calledino
 	絵



More information about the Vegan-commits mailing list