Error message
Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home3/gardeoi3/public_html/iamrandom/includes/common.inc).
Rcpp
By tholscla on Wed, 06/11/2014 - 12:18
This is a quick test Rcpp module to ensure Rcpp was installed and linked properly to R. Just run these lines of code in R and the answer should be 9 at the end.
library(Rcpp)
library(inline)
fx <- cxxfunction(,"",includes=
' double add(double c,double d)
{ double e=0;
e=c+d;
return e;
}
RCPP_MODULE(foo)
{ function( "add", &add ) ;}
', plugin="Rcpp")
foo <- Module("foo",getDynLib(fx))
foo$add(4,5) #answer is 9
By tholscla on Fri, 05/02/2014 - 13:17
// is the format for adding comments in Rcpp
int n= b.size(); //finds the length of a vector b
int m=B.nrow(); //finds the number of rows in a matrix
double x=runif(1)(0); //gets one random Uniform(0,1); runif returns a vector so we just use element (0).
pow(), not ^, for exponentiation.
sqrt() and exp() work
for a function that returns nothing use void func_name(int a){ return; }
By tholscla on Thu, 02/27/2014 - 22:27
Rcpp works well with Unix/Linux. Setting it up on Windows takes some work. Use the standard settings on all of these installs. (updated 2/2014)
By tholscla on Sat, 11/02/2013 - 10:53
Wraps R.rgamma for correct input and output
double rgammadouble(int a, double b, double c)
{ Rcpp::NumericVector x = rgamma(a,b,1/c);
return x(0);
}
By tholscla on Sat, 11/02/2013 - 10:52
Wraps R.rbinom for correct input and output
double rbinomint(int a, int b, double c)
{ Rcpp::NumericVector x = rbinom(a,b,c);
return x(0);
}
By tholscla on Sat, 11/02/2013 - 10:52
Wraps R.rnorm for correct input and output.
double rnormdouble(int a, double b, double c)
{ Rcpp::NumericVector x = rnorm(a,b,c);
return x(0);
}
By tholscla on Sat, 11/02/2013 - 10:51
Wraps R.runif for correct input and output.
double runifdouble()
{ Rcpp::NumericVector x = runif(1);
return x(0);
}
By tholscla on Sat, 11/02/2013 - 10:49
Draw one of {1,..,K} with probabilities "probf"
Needs function: sumv
By tholscla on Sat, 11/02/2013 - 10:45
This is the same as the R function sum when used on a vector.
double sumv(Rcpp::NumericVector A)
{ int na= A.size();
double b=0;
for (int i = 0; i < na; i++)
{ b=b+A(i);
}
return b;
}
By tholscla on Sat, 11/02/2013 - 10:41
In R this would be A%*%B. In Rcpp it is matmul(A,B).
### Calls function: dot
Rcpp::NumericMatrix matmul(Rcpp::NumericMatrix A,Rcpp::NumericMatrix B)
{ int a= A.nrow();
int b= B.ncol();
Rcpp::NumericMatrix C(a,b);
for (int i = 0; i < a; i++)
{ for (int j = 0; j < b; j++)
{ C(i,j)= dot(A(i,_),B(_,j));
}
}
return C;
}
Pages