Displaying 20 results from an estimated 2000 matches similar to: "GetRNGstate() crashes in Windows"
2004 Mar 03
1
generating normal numbers: GetRNGstate, PutRNGstate
Hi
I'd like to generate thousands 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
2008 Jul 03
1
GetRNGstate and PutRNGstate
Hi,
I've got a simulation function, written in C and called 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
2002 Jan 14
1
trouble using R Mathlib as standalone
Dear People,
I am trying to use R's Math library as standalone, as documented in
/src/nmath/standalone. I am using C++ in Debian testing, and the versions
are as follows:
ii g++-3.0 3.0.3-1 The GNU C++ compiler.
ii r-mathlib 1.4.0-1 `GNU S' - Standalone R math library
I have a file (rand.cc) as follows. I don't think that lattice.hh or mh.hh
are very
2006 Feb 21
4
simple C function segfaults
Hello,
I use the simplest of examples that somebody can think
of in order to generate a matrix of random numbers
from within C, calling 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,
2006 Mar 07
2
double pointer matrix
Hello,
I'm having some difficulty to understand how I could
take the proper result from the following listing:
-- cut ---
#include <stdlib.h>
#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 (
2010 Jun 15
1
Error when callin g C-Code
Hi
when I call the function below in R, i get the error: Object 'pairlist'
can't be converted to 'double'.
#include <R.h>
#include <Rdefines.h>
#include <Rmath.h>
SEXP CSimPoisson(SEXP lambda, SEXP tgrid, SEXP T2M, SEXP Ni, SEXP NT)
{
double sign, EVar;
double *xlambda, *xtgrid, *xT2M, *xNi, *xNT, *xtau;
SEXP tau;
int ltgrid =0;
int i = 0;
int j = 0;
2005 Nov 30
1
RNG stuck via Fortran call
Having not much success with my previous question I try to reformulate it:
I'm simulating a Markow chain in Fortran interfaced with R.
Each loop of my Fortran calls various functions of the R RNG through
the wrapper given below.
In a run of 100 iterations of the Markov kernel,
after 20 iterations, the RNG seems like frozen.
For example, the first call to the RNG in my loop is:
2005 Jun 14
3
Calling C from Fortran
I would like to call C routines from Fortran under linux as suggested in
section 5.6 of
the "Writing R extensions" documentation.
I'm familiar with Fortran but not with C.
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
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
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
2009 Jun 30
3
Matrix with random number
Hello!
I have a program 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
2005 Jun 14
1
Calling C from Fortran
I would like to call C routines from Fortran as suggested in section 5.6 of
the "Writing R extensions" documentation.
I'm familiar with Fortran but not with C.
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
2006 Aug 03
1
question about dll crashing R
I have ported some R code to C to make it faster.
I can perform .Call("foobar",....) once and it
works fine. Absolutely correct answer.
If I put a loop inside foobar and run the main code
routine more than 100 times, it crashes R.
Or if I call .Call("foobar"....) seperately more than
two tims it crashes R.
For the most part I am doing matirx multiplies using
EXP
2011 Nov 17
3
.Call in R
Hi R developers,
I am new to this forum and hope someone can help me with .Call in R.
Greatly appreciate any help!
Say, I have a vector called "vecA" of length 10000, I generate a vector
called "vecR" with elements randomly generated from Uniform[0,1]. Both vecA
and vecR are of double type. I want to replace elements vecA by elements in
vecR only if sum of elements in
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
2016 Jul 01
1
Calling C implementations of rnorm and friends
Well,
For this particular use case why not just transform the parameters at the R
level and then call the existing function? Is there not a closed form
mapping?
~G
On Jul 1, 2016 2:50 PM, "Joshua Ulrich" <josh.m.ulrich at gmail.com> wrote:
> On Fri, Jul 1, 2016 at 6:13 AM, Luis Usier
> <luis.henrique.usier at gmail.com> wrote:
> > Gabriel,
> >
> >
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 =>
2007 May 12
2
Problem with rnorm ?
Hi,
I couldn't get the rnorm() work right in C, for example, the following code produce strange results.
#include <stdio.h>
#include <Rmath.h>
int main(void){
double x[3];
for(int i=0;i<3;i++) x[i]=rnorm(0,1);
printf("%lf,%lf,%lf",x[0],x[1],x[2]);
return 0;
}
output : -8.773321,-8.773321,-8.773321
compiling script: gcc -std=gnu99 -Wall
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 Jul 20
1
Call to rgamma using .C causes R to hang
Hi,
I've been trying to get this working for ages, but it causes R to hang.
Here is my C code saved as test1.c
# include <R.h>
# include <Rmath.h>
void test1 (double *x, double *result)
{
result[0] = rgamma(*x, 2.0);
}
This was compiled using R CMD SHLIB test1.c & loaded in R using:
dyn.load("test1.dll")
out <-