search for: getrngstat

Displaying 20 results from an estimated 45 matches for "getrngstat".

Did you mean: getrngstate
2004 Mar 03
1
generating normal numbers: GetRNGstate, PutRNGstate
...usands of normal numbers from my C function using the C API functions provided R. I have two options: 1. double norm_rand(); (page 61 of R extension 1.8.1) 2. double rnorm(double mu, double sigma); (page 58 of R extension 1.8.1) If my understanding of R-exts is correct, then I only need to call GetRNGstate once, and then call 1000 norm_rand, and then call PutRNGstate once for the 1st option. For the 2nd option, I have to call 1000 times for each of GetRNGstate, rnorm, and PutRNGstate. The pseudo-code for option 1 will be: Method 1: GetRNGstate(); for(i=1;i<1000;i++){ x[i]=norm_rand(); }...
2005 Jun 28
1
GetRNGstate() crashes in Windows
Hi, Has anyone managed to successfully call GetRNGstate() / PutRNGstate() without crashing in a Windows environment (spec. XP)? I've compiled successfully using both the latest Cygwin, latest Mingw, and the version of Mingw suggested in "Building R for Windows" website, but when the executable runs, it crashes; the functions themselv...
2008 Jul 03
1
GetRNGstate and PutRNGstate
...lled from R, that uses the R random number functions. It's not a very complicated simulation - 280 lines total, with the main function (the one called with .C) repeatedly calling another function, with multiple calls to unif_rand() in both functions. At the beginning of the main function I call GetRNGstate(), and the last thing I do before returning to R is PutRNGstate(). On rereading Chapter 5 of the R Extensions manual, I'm not sure I understand the GetRNGstate/PutRNGstate calls. Should I also include them in the helper function? Do I need to wrap every call to unif_rand with these calls, or...
2002 Dec 20
1
GetRNGstate() crashes with 'Segmentation fault'
Dear R-masters, I tried to compile this simpel C-code: //----------------- #include<R.h> int main() { GetRNGstate(); return 0; } //----------------- Compiling: ~> gcc -o a a.c -I/usr/lib/R/include/ -L/usr/lib/R/bin/ -lR ~> ldd a libR.so => /usr/lib/libR.so (0x40018000) libc.so.6 => /lib/libc.so.6 (0x401a8000) libblas.so.2 => /usr/lib/libblas.so.2 (0x402bb000)...
2002 Jan 24
2
random number generation issues with r and compiled C code
...looks like there is no perfect solution to the problem of generating random numbers in C/C++. So, I'm thinking of running my program inside R by compiling my code as a shared library, and using R's builtin random number facilities. I have a couple of questions about this. 1) The functions GetRNGstate() and PutRNGetate() read and write .Random.Seed. The question is what is the best strategy for calling these. Would it be best to call these routines as infrequently as possible? My remarks above (if correct) suggest that. That is, would be best to call GetRNGstate() once before generating all ran...
2002 Jan 14
1
trouble using R Mathlib as standalone
...rent errors. The first one I am completely mystified by. It seems to have something to do with a double declaration of log1p which I have not used and not knowingly declared twice in any way. Neither lattice.hh nor mh.hh contain any math headers. The second one clearly has to do with the usage of GetRNGstate() and PutRNGstate() which are correct for use as entry points into the R executable but no longer correct for standalone usage. The README in the standalone directory said something about using the uniform random number generator, but gave no examples so I didn't understand. Can someone tell m...
2006 Jan 05
2
random seed question
Greetings, I am trying to write a C++ subroutine of my random number generator. Based on tutorial in Writing R Extensions, one should call GetRNGstate() before and PutRNGstate() after calling R's random variate generation routines. Now suppose my function would generate n(n>1) numbers by a loop, do I need to call these two functions at each iteration? This certainly increases computation burden (although indiscernible in my case). But if...
2006 Feb 21
4
simple C function segfaults
...g appropriate R functions. The concrete example is below: --- file pico.c #include <stdio.h> #include <stdlib.h> #include <math.h> #include <R.h> #include <Rmath.h> #define COLM( i, j, m ) ( m*j + i) void pico ( double *y, int n, int m ) { int i, j; GetRNGstate(); for ( i=0; i<n; i++ ) { for ( j=0; j<m; j++ ) { y[ COLM( i,j,m ) ] = rnorm( 0, 1 ); } } PutRNGstate(); } --------- --- file pico.R dyn.load("pico.so"); if( is.loaded( symbol.C( "pico" )...
2006 Mar 07
2
double pointer matrix
...; #include <R.h> #include <Rmath.h> void retMat ( double **y, int *n, int *m, double *a, double *b) { int i, j; y = malloc( (*n) * sizeof( double ) ); for (i=0; i<*n; i++) { y[i] = malloc ( (*m) * sizeof( double ) ); } GetRNGstate(); for (i=0; i<*n; i++) { for (j=0; j<*m; j++) { y[i][j] = (i+1)*(j+1)*rbeta( *a, *b ); } } PutRNGstate(); } --- I understand that I will have to make the matrix initialized in the double for loop above...
2005 Jun 14
3
Calling C from Fortran
.... I understand the example provided in Fortran: subroutine testit() double precision normrnd, x call rndstart() x = normrnd() call dblepr("X was", 5, x, 1) call rndend() end but I don't understand the purpose of this C wrapper: #include <R.h> void F77_SUB(rndstart)(void) { GetRNGstate(); } void F77_SUB(rndend)(void) { PutRNGstate(); } double F77_SUB(normrnd)(void) { return norm_rand(); } neither how I should compile it. Could anyone explain how I should compile and link the C and Fortran files above, and call the Fortran subroutine from R. Thanks, Gilles
2005 Jun 14
1
Calling C from Fortran
.... I understand the example provided in Fortran: subroutine testit() double precision normrnd, x call rndstart() x = normrnd() call dblepr("X was", 5, x, 1) call rndend() end but I don't understand the purpose of this C wrapper: #include <R.h> void F77_SUB(rndstart)(void) { GetRNGstate(); } void F77_SUB(rndend)(void) { PutRNGstate(); } double F77_SUB(normrnd)(void) { return norm_rand(); } neither how I should compile it. Could anyone explain how I should compile and link the C and Fortran files above, and call the Fortran subroutine from R. Thanks, Gilles
2009 Nov 13
2
random numbers in C
I need some random numbers in my C program. Here a small example: //////////////////////////////////////////////////////////////////////////////// #include <R.h> void rand (int* n) { int len = *n; for (int i = 0; i < len; i++) Rprintf("%1.5f ", unif_rand()); } dyn.load("rand.dll") .C("rand", as.integer(10)) dyn.unload("rand.dll")
2010 Jun 15
1
Error when callin g C-Code
...AS_NUMERIC(T2M)); PROTECT(Ni = AS_NUMERIC(Ni)); PROTECT(NT = AS_NUMERIC(NT)); PROTECT(tau = NEW_NUMERIC(1)); xlambda = NUMERIC_POINTER(lambda); xtgrid = NUMERIC_POINTER(tgrid); xT2M = NUMERIC_POINTER(T2M); xNi = NUMERIC_POINTER(Ni); xNT = NUMERIC_POINTER(NT); xtau = NUMERIC_POINTER(tau); GetRNGstate(); if(xlambda[0] != 0) { while(1) { EVar = rexp(xlambda[0]); sign = sign + EVar; if (sign > xT2M[0]) { break; } xtau = Realloc(xtau, i+1, double); xtau[i] = sign; i = i+1; for(j; j < ltgrid;j++) { if (xtgrid[j] < sign) { xNi[j] = xNT[0]...
2005 Nov 30
1
RNG stuck via Fortran call
...ng interations. Is there any suggestion of explanation for this strange fact ? Thanks in advance Gilles R Version 2.2.0 compiled under Mandrake 10.1 #include <R.h> #include <Rmath.h> /******************/ /* random numbers */ /******************/ void F77_SUB(rndstart)(void) { GetRNGstate(); } void F77_SUB(rndend)(void) { PutRNGstate(); } double F77_SUB(ggrnorm)(double *mu, double *sigma) { return rnorm(*mu, *sigma); } double F77_SUB(ggrexp)(double *scale) {return rexp(*scale);} double F77_SUB(ggrgam)(double *a, double *scale) {return rgamma(*a, *scale);} double F77_SUB(ggru...
2012 Jan 05
1
Calling R functions within C/C++
...from within my C++ code. (There may be an equivalent of the rep function already in C++ but my main interest here is to learn if there is a way to call the R function within C/C++) I'm aware that you can call R random number generators as well as probability distribution functions with the GetRNGstate() but what about other functions? The sample of the C code below reveals what I would like to do regarding the rep function. extern "C" { void Gibbs_Sampler (double *vect.PI, int *iteration) { int i; for (int i=0; i<*iteration; i++)...
2009 Jun 30
3
Matrix with random number
...am in Fortran and would like to build a matrix with random numbers, I have a function in C. However, I have problems with the use of function in R. Code to compile: R CMD SHLIB mat.f myrbeta.c -o func.so Code in C. #include <R.h> #include <Rmath.h> void F77_SUB(fseedi)(void){   GetRNGstate(); } void F77_SUB(fseedo)(void){   PutRNGstate(); } void F77_SUB(myrbeta)(double *px, double *pa, double *pb){   *px = rbeta(*pa,*pb); } Code in Fortran     subroutine mat(x,l,c)     integer l,c     double precision x(l,c)     integer i,j      do j = 1, c        do i = 1, l         call fse...
2006 Aug 03
1
question about dll crashing R
...getAttrib (mean , R_DimSymbol ) ; ydims = getAttrib (cov , R_DimSymbol ) ; mode = REALSXP; nrx = INTEGER( xdims ) [ 0 ] ; ncx = INTEGER( xdims ) [ 1 ] ; nry = INTEGER( ydims ) [ 0 ] ; ncy = INTEGER( ydims ) [ 1 ] ; /* create the upper trianglular matrix A */ /* such that t(A) %*% A = Sigma */ GetRNGstate(); F77_CALL(dpofa) ( REAL( cov ), &nry , &ncy , &info); Rprintf("Info = %d\n",info); for(i=0;i<nry;i++) for(j=0;j<i;j++) REAL(cov)[i+j*ncy] = 0.0; PROTECT( ans = allocMatrix (mode, nrx , one ) ) ; for(i=0;i<nry;i++) REAL(temp)[i] = rnorm(0,1); ans = tma...
2011 Nov 17
3
.Call in R
..._ptr,*vecR_ptr,*vecA_ptr; vecA_ptr=REAL(vecA); vecA_len=length(vecA); SEXP res_vec,vecR; PROTECT(res_vec=allocVector(REALSXP, vec_len)); PROTECT(vecR=allocVector(REALSXP, vec_len)); res_ptr=REAL(res_vec); vecR_ptr=REAL(vecR); GetRNGstate(); sum=0.0; for (i=0;i<vecA_len;i++){ vecR_ptr[i]=runif(0,1); sum+=vecR_ptr[i]; } if (sum>=5000){ /*copy vecR to the vector to be returned*/ for (i=0;i<vecA_len;i++){ res_ptr[i]=vecR_...
2008 Jul 18
1
system time - windows specific problem
...e R source. Of course, I look there my code is based on this code. But in the RNG.c file which implements random number generation. they use line 271-289 #include <time.h> #ifdef HAVE_SYS_TIME_H # include <sys/time.h> #endif static void Randomize(RNGtype kind) { /* Only called by GetRNGstate() when there is no .Random.seed */ Int32 seed; #if HAVE_GETTIMEOFDAY { struct timeval tv; gettimeofday (&tv, NULL); seed = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; } #elif HAVE_TIME seed = (Int32) time(NULL); #else /* unlikely, but use random content...
2015 Apr 21
2
shlib problems with Intel compiler
...eans.o cshell.o floyd.o svm.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' Rsvm.o: In function `do_cross_validation': /tmp/Rtmp9h7iYE/R.INSTALL1d9615a42180e/e1071/src/Rsvm.c:91: undefined reference to `GetRNGstate' /tmp/Rtmp9h7iYE/R.INSTALL1d9615a42180e/e1071/src/Rsvm.c:94: undefined reference to `unif_rand' /tmp/Rtmp9h7iYE/R.INSTALL1d9615a42180e/e1071/src/Rsvm.c:106: undefined reference to `PutRNGstate' ... (many more undefined references) -- Andy Jacobson andy.jacobson at noaa.gov NOAA E...