Skip to content

Commit

Permalink
next
Browse files Browse the repository at this point in the history
  • Loading branch information
chung@molgen.mpg.de committed Jan 19, 2016
1 parent 821cca8 commit 9fe7c4d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Maintainer: Who to complain to <yourfault@somewhere.net>
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
Imports:
Rcpp,
RcppGSL
LinkingTo:
Rcpp,
RcppGSL
11 changes: 11 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -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)
}

4 changes: 4 additions & 0 deletions configure.old
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"`
31 changes: 31 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// This file was generated by Rcpp::compileAttributes
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <RcppGSL.h>
#include <Rcpp.h>

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
}
27 changes: 27 additions & 0 deletions src/rmn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// [[Rcpp::depends(RcppGSL)]]

#include <RcppGSL.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <unistd.h> // 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;
}



0 comments on commit 9fe7c4d

Please sign in to comment.