[Vegan-commits] r1834 - in pkg/vegan: inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Sep 10 08:16:55 CEST 2011


Author: jarioksa
Date: 2011-09-10 08:16:55 +0200 (Sat, 10 Sep 2011)
New Revision: 1834

Modified:
   pkg/vegan/inst/ChangeLog
   pkg/vegan/src/nestedness.c
Log:
faster isDiag*: get out quickly if you only can

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-09-10 05:17:12 UTC (rev 1833)
+++ pkg/vegan/inst/ChangeLog	2011-09-10 06:16:55 UTC (rev 1834)
@@ -9,8 +9,14 @@
 
 	* permatswap: there was a bug in internal C routine, and therefore
 	not all permissible swaps were performed. Based on limited
-	analysis, the effects of this bug seem to be negligible. 
-	It is, however, recommended to re-run all analyses.
+	analysis, the effects of this bug seem to be negligible.  It is,
+	however, recommended to re-run all analyses. The C code was made
+	faster by getting quickly out from isDiag* if there are only 0 or
+	1 filled items, because there is nothing to swap. Tests show that
+	the C code indeed is ca 10% faster in permatswap(BCI,
+	method="swa", thin=1000, times=999), but only a 20-25% of time was
+	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.
 
 	* New functions: permatfull1 and permatswap1. Both functions
 	return a single permuted matrix. These functions are now 

Modified: pkg/vegan/src/nestedness.c
===================================================================
--- pkg/vegan/src/nestedness.c	2011-09-10 05:17:12 UTC (rev 1833)
+++ pkg/vegan/src/nestedness.c	2011-09-10 06:16:55 UTC (rev 1834)
@@ -179,8 +179,8 @@
 	    if (sm[i] > 0)
 		    sX++;
 
-    /* quick return if there really is nothing to do */
-    if (sX == 0)
+    /* quick return: you cannot swap 0 or 1 items */
+    if (sX < 2)
         return 0;
 
     /* Smallest diagonal and antidiagonal element */
@@ -201,13 +201,19 @@
 	(sm[0] > 0 && sm[1] == 0 && sm[2] > 0 && sm[3] > 0) ||
 	(sm[0] > 0 && sm[1] > 0 && sm[2] == 0 && sm[3] > 0))
 	    return choose[1];
-    if (sX < 2 ||
-	(sm[0] == 0 && sm[1] == 0 && sm[2] > 0 && sm[3] > 0) ||
-	(sm[0] > 0 && sm[1] > 0 && sm[2] == 0 && sm[3] == 0) ||
-	(sm[0] == 0 && sm[1] > 0 && sm[2] == 0 && sm[3] > 0) ||
-	(sm[0] > 0 && sm[1] == 0 && sm[2] > 0 && sm[3] == 0))
-	    return 0; 
-    /* never reach this but pacify a pedantic compiler */
+ 
+   /* The following is unnecessary, because next 'else' will return 0
+     * even if this if(...) is false */
+
+/*
+ *  if (sX < 2 ||
+ *	(sm[0] == 0 && sm[1] == 0 && sm[2] > 0 && sm[3] > 0) ||
+ *	(sm[0] > 0 && sm[1] > 0 && sm[2] == 0 && sm[3] == 0) ||
+ *	(sm[0] == 0 && sm[1] > 0 && sm[2] == 0 && sm[3] > 0) ||
+ *	(sm[0] > 0 && sm[1] == 0 && sm[2] > 0 && sm[3] == 0))
+ *	    return 0;
+ */ 
+
     else
 	 return 0;
 }
@@ -323,8 +329,8 @@
     for (i = 0, sX = 0; i < 4; i++)
 	if (sm[i] > 0)
 	    sX++;
-
-    if (sX == 0)
+    /* quickly out: you cannot swap 0 or 1 items */
+    if (sX < 2)
 	return 0;
     if (sX == 4) {
 	return 1;



More information about the Vegan-commits mailing list