diff --git a/DESCRIPTION b/DESCRIPTION index 8f4e803..da8bb63 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,9 @@ Maintainer: Who to complain to Description: More about what it does (maybe more than one line) License: What license is it under? LazyData: TRUE -Imports: - Rcpp (>= 0.12.1) -LinkingTo: - Rcpp \ No newline at end of file +Imports: + Rcpp, + RcppGSL +LinkingTo: + Rcpp, + RcppGSL diff --git a/R/RcppExports.R b/R/RcppExports.R new file mode 100644 index 0000000..df8b9b2 --- /dev/null +++ b/R/RcppExports.R @@ -0,0 +1,11 @@ +# This file was generated by Rcpp::compileAttributes +# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +init_rng <- function(seed = 0L) { + .Call('decon_init_rng', PACKAGE = 'decon', seed) +} + +rmn <- function(N, p) { + .Call('decon_rmn', PACKAGE = 'decon', N, p) +} + diff --git a/configure.old b/configure.old new file mode 100755 index 0000000..d12ab53 --- /dev/null +++ b/configure.old @@ -0,0 +1,4 @@ +#!/bin/sh +GSL_CFLAGS=`${R_HOME}/bin/Rscript -e "RcppGSL:::CFlags()"` +GSL_LIBS=`${R_HOME}/bin/Rscript -e "RcppGSL:::LdFlags()"` +sed -e "s|@GSL_LIBS@|${GSL_LIBS}|" -e "s|@GSL_CFLAGS@|${GSL_CFLAGS}|" src/Makevars.in > src/Makevars diff --git a/src/Makevars b/src/Makevars new file mode 100644 index 0000000..1d9806c --- /dev/null +++ b/src/Makevars @@ -0,0 +1 @@ +PKG_LIBS = `$(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"` diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp new file mode 100644 index 0000000..2ac023c --- /dev/null +++ b/src/RcppExports.cpp @@ -0,0 +1,31 @@ +// This file was generated by Rcpp::compileAttributes +// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +#include +#include + +using namespace Rcpp; + +// init_rng +long init_rng(long seed); +RcppExport SEXP decon_init_rng(SEXP seedSEXP) { +BEGIN_RCPP + Rcpp::RObject __result; + Rcpp::RNGScope __rngScope; + Rcpp::traits::input_parameter< long >::type seed(seedSEXP); + __result = Rcpp::wrap(init_rng(seed)); + return __result; +END_RCPP +} +// rmn +Rcpp::IntegerVector rmn(unsigned int N, Rcpp::NumericVector p); +RcppExport SEXP decon_rmn(SEXP NSEXP, SEXP pSEXP) { +BEGIN_RCPP + Rcpp::RObject __result; + Rcpp::RNGScope __rngScope; + Rcpp::traits::input_parameter< unsigned int >::type N(NSEXP); + Rcpp::traits::input_parameter< Rcpp::NumericVector >::type p(pSEXP); + __result = Rcpp::wrap(rmn(N, p)); + return __result; +END_RCPP +} diff --git a/src/rmn.cpp b/src/rmn.cpp new file mode 100644 index 0000000..46d6aaf --- /dev/null +++ b/src/rmn.cpp @@ -0,0 +1,27 @@ +// [[Rcpp::depends(RcppGSL)]] + +#include +#include +#include +#include // getpid + +gsl_rng* r; + +long init_rng(long seed = 0){ + r = gsl_rng_alloc (gsl_rng_mt19937); + if (seed == 0){ + seed = rand()/(((double)RAND_MAX + 1)/10000000) * getpid(); + } + gsl_rng_set (r, seed); + return seed; +} + +Rcpp::IntegerVector rmultinom(unsigned int N, Rcpp::NumericVector p){ + size_t K = p.size(); + Rcpp::IntegerVector res(K); + gsl_ran_multinomial(r, K, N, p.begin(), (unsigned int *) res.begin()); + return res; +} + + +