search for: putrngstate

Displaying 20 results from an estimated 42 matches for "putrngstate".

2004 Mar 03
1
generating normal numbers: GetRNGstate, PutRNGstate
...nctions 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(); } PutRNGstate(); The pseudo code for option 2 will be: Method 2:...
2008 Jul 03
1
GetRNGstate and PutRNGstate
...ot 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 is it ok that I've just used them at the beginning and end of...
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 themselves can run when I...
2002 Jan 14
1
trouble using R Mathlib as standalone
...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 me what the correct...
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 I only call them once (ou...
2006 Feb 21
4
simple C function segfaults
...h.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" ) ) ) n<-10; m<-5; y<-matrix( 0, n, m ); a<- .C( "pico", as.double(y), as.integer(n), as.integer(m) ); ----- The code, when executed within R, gives a segmentation faul...
2006 Mar 07
2
double pointer matrix
...lt;*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 to be somehow visible as a vector, because of the way that the matrix elements are passed in the argument when used in the R space. Is there a way to accomplish this? Thanks for any answers, - b.
2005 Jun 14
3
Calling C from 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 Jul 30
3
user supplied random number generators
?Random.user says (in svn trunk) Optionally, functions \code{user_unif_nseed} and \code{user_unif_seedloc} can be supplied which are called with no arguments and should return pointers to the number of seeds and to an integer array of seeds. Calls to \code{GetRNGstate} and \code{PutRNGstate} will then copy this array to and from \code{.Random.seed}. And it offers as an example void user_unif_init(Int32 seed_in) { seed = seed_in; } int * user_unif_nseed() { return &nseed; } int * user_unif_seedloc() { return (int *) &seed; } First question: what is the lifetime of the...
2005 Jun 14
1
Calling C from 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
...{ 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]; } { break; } } xNT[0] = xNT[0] + 1; } for(j;j < ltgrid;j++) { xNi[j] = xNT[0]; } } PutRNGstate(); UNPROTECT(6); return tau; }
2005 Nov 30
1
RNG stuck via Fortran call
...anation 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(ggrunif)(double *a, double *b) {return runif(*a, *b);...
2009 Jun 30
3
Matrix with random number
...ith 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 fseedi()          x(i,j) = call myrbeta(1,4,5) ! It...
2006 Aug 03
1
question about dll crashing R
...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 = tmatrixprod(cov,temp); for(i=0;i<nry;i++) REAL(ans)[i] = REAL(ans)[i]+REAL(mean)[i]; UNPROTECT( 1 ) ; PutRNGstate(); return( ans ) ; } I have a feeling I am messing up memory usage somewhere but haven't a clue. Do I need to do garbage collecting inside the C program ?The fact that the code runs a few times before R crashes is driving me nuts. I send most of what I need into the C routine from R, so I...
2011 Nov 17
3
.Call in R
...for (i=0;i<vecA_len;i++){ res_ptr[i]=vecR_ptr[i]; } } else{ /*copy vecA to the vector to be returned*/ for (i=0;i<vecA_len;i++){ res_ptr[i]=vecA_ptr[i]; } } PutRNGstate(); UNPROTECT(2); resturn(res); } My R wrapper function is change_vecA<-function(vecA){ dyn.load("change_vecA.so"); .Call("change_vecA",vecA); } Now my question is, due to two loops (one generates the r...
2015 Apr 21
2
shlib problems with Intel compiler
...lidation': /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 Earth System Research Lab Global Monitoring Division 325 Broadway R/GMD1 Boulder, Colorado 80305 303/578-2237
2002 Jan 24
2
random number generation issues with r and compiled C code
Dear People, I have been writing a simulation routine that is currently entirely written in c++. I've been using the R standalone math library to give me random number generation for this. However, I have had to set the seed myself, and I am using set_seed(time(NULL), clock) for every call to unif_rand(). However, this works really badly. The random numbers aren't uniform at all. Does
2006 Jun 08
1
Problems Building R-2.3.1 on Alpha server ES40 running Tru64 V5.1B PK#5
...lpng -lz -rpath /opt/libpng /lib:/opt/libjpeg/lib:/opt/ncurses/lib:/opt/gnu/lib:/usr/shlib:/opt/zlib /lib:/opt/R/lib -o MASS.so MASS.o lqs.o ld: Warning: Unresolved: exp fabs pow sqrt isnan Rf_error R_alloc Rprintf R_chk_calloc R_chk_free vmmin R_registerRoutines R_useDynamicSymbols log GetRNGstate PutRNGstate unif_rand R_rsort Rf_rPsort R_CheckUserInterrupt dqrsl_ dqrdc2_ make[3]: Leaving directory `/cluster/members/member0/tmp/R.INSTALL.OVYGvZ/VR/MASS/src' chmod: cannot access `/usr/ruby-deploy/swkits/RUBY/SOFTWARE/3rdPartySW/R/R-2.3.1/build/librar y/MASS/libs//*': No such file or directory **...
2013 Jun 07
0
[Rcpp-devel] Setting the R random seed from Rcpp
....Random.seed <- savedSeed > > x1 <- Rfunction(parameters2); > > > > where Rfunction simulates some random numbers and uses them > > but with different parameter values. > > Is it possible to do something similar in Rcpp? > > Probably using GetRNGstate() and PutRNGstate()? > > > > Thanks, > > > > Matteo > > _______________________________________________ > > Rcpp-devel mailing list > > Rcpp-devel at lists.r-forge.r-project.org > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel > __________...