[Picante-commits] r147 - in branches/gsoc: R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jul 23 05:36:25 CEST 2008


Author: skembel
Date: 2008-07-23 05:36:25 +0200 (Wed, 23 Jul 2008)
New Revision: 147

Modified:
   branches/gsoc/R/randomizeSample.R
   branches/gsoc/src/picante.c
Log:
Update trialswap R and C code to deal with doubles

Modified: branches/gsoc/R/randomizeSample.R
===================================================================
--- branches/gsoc/R/randomizeSample.R	2008-07-23 02:58:32 UTC (rev 146)
+++ branches/gsoc/R/randomizeSample.R	2008-07-23 03:36:25 UTC (rev 147)
@@ -14,10 +14,11 @@
 	    return(t(data.frame(apply(samp,1,sample),row.names=colnames(samp))))
 	}
 	if (identical(null.model,"both")) 
-  {
-    ret1<-.C("trialswap",m=as.integer(samp),as.integer(it),as.integer(nrow(samp)),as.integer(ncol(samp)),PACKAGE="picante")
-    return(matrix(ret1$m,nrow=nrow(samp)))        
-        
+    {
+    ret1 <- .C("trialswap", m=as.numeric(samp), as.integer(it), as.integer(nrow(samp)), as.integer(ncol(samp)), PACKAGE="picante")
+    return(matrix(ret1$m,nrow=nrow(samp)))
+	}
+	
 #  #check for presence-absence and warn until abundance implemented
 #        x <- decostand(samp, "pa")
 #        if (!identical(x,samp)) stop("Null model currently requires a presence-absence matrix.")
@@ -45,6 +46,6 @@
 #            mergedFrame[is.na(mergedFrame)] <- 0
 #            return(mergedFrame[rownames(x),colnames(x)])
 #        }
-	}
+
 }
 

Modified: branches/gsoc/src/picante.c
===================================================================
--- branches/gsoc/src/picante.c	2008-07-23 02:58:32 UTC (rev 146)
+++ branches/gsoc/src/picante.c	2008-07-23 03:36:25 UTC (rev 147)
@@ -42,6 +42,7 @@
   int i,j,k,l;
   int row, column;
   int intervals;
+	double tmp;
   double **m;
 
   row = *prow;
@@ -57,13 +58,15 @@
       while((j=intrand(row))==i);
       k=intrand(column);
       while((l=intrand(column))==k);
-      if((m[i][k]*m[j][l]==1 && m[i][l]+m[j][k]==0)||(m[i][k]+m[j][l]==0 && m[i][l]*m[j][k]==1))
-	{
-	  m[i][k]=1-m[i][k];
-	  m[i][l]=1-m[i][l];
-	  m[j][k]=1-m[j][k];
-	  m[j][l]=1-m[j][l];
-	}
+      if((m[i][k]>0.0 && m[j][l]>0.0 && m[i][l]+m[j][k]==0.0)||(m[i][k]+m[j][l]==0.0 && m[i][l]>0.0 && m[j][k]>0.0))
+		{
+		  tmp = m[i][k];
+		  m[i][k] = m[j][l];
+		  m[j][l] = tmp;
+		  tmp = m[j][k];
+		  m[j][k] = m[i][l];
+		  m[i][l] = tmp;
+		}
     }
   mattovec(v,m,row,column);
   PutRNGstate();



More information about the Picante-commits mailing list