[Rd] The following code (using rgamma) hangs

From: Faheem Mitha <faheem_at_faheem.info>
Date: Sat, 28 Jan 2012 02:33:05 +0530 (IST)

Hi,

I'm seeing something that may be a bug in R's standalone math library, which is packaged by Debian as r-mathlib. I reported it to the Debian BTS as http://bugs.debian.org/657573

I'm using Debian squeeze, and the code was tested with r-mathlib 2.11.1-6 (default on stable) and 2.14.1-1 (from testing/unstable).

I summarize this report below. The following code with the R math library hangs. Note that set_seed is defined as taking two unsigned int arguments, so 0's are valid arguments. I'm guessing that since 0 is as low as an unsigned integer can go, it represents some kind of edge case.

################################################
#define MATHLIB_STANDALONE
#include <Rmath.h>

int main(void)
{

   set_seed(0, 0);
   rgamma(1, 1);
}

################################################

If I add the definitions of `get_seed` and `set_seed` from `src/nmath/standalone/sunif.c` to my code, then the hang disappears.

################################################
#define MATHLIB_STANDALONE
#include <Rmath.h>

/* A version of Marsaglia-MultiCarry */

static unsigned int I1=1234, I2=5678;

void set_seed(unsigned int i1, unsigned int i2)
{

     I1 = i1; I2 = i2;
}

void get_seed(unsigned int *i1, unsigned int *i2)
{

     *i1 = I1; *i2 = I2;
}

int main(void)
{

   set_seed(0, 0);
   rgamma(1, 1);
}

################################################

I assume sunif.c defines the `get_seed` and `set_seed` for the R standalone random number generation facilities.

However, I wonder why

  1. redefining them in my source file makes the hang go away

and

b) why doesn't redefining `get_seed` and `set_seed` (even with the same definition) give a linker error, since the function has been defined in the library already?

Dirk also pointed out (in the bug report) that you get the following

##########################################################
int main(void)
{
     set_seed(0, 0);
     cout << "one normal " << norm_rand() << endl;
}
##########################################################

edd_at_max:/tmp$ g++ -o faheem faheem.cpp -lRmath; ./faheem one normal -inf

One would expect norm_rand to return finite values, even in edge cases.

If you want me to report this as a bug, let me know. Thanks.

                                                        Regards, Faheem

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 27 Jan 2012 - 21:05:53 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 27 Jan 2012 - 21:40:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive