[R] trouble using R Mathlib as standalone
Faheem Mitha
faheem at email.unc.edu
Mon Jan 14 22:43:56 CET 2002
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 relevant. The class Cube is defined in lattice.hh and I don't
think mh.hh are used at all. I get the following errors when trying to
compile this. Of course these cannot be reproduced without all my files,
but I am hoping these errors have nothing to do with my code and that the
answer will be obvious to those in the know.
I get two different 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
me what the correct syntax should be in this case?
Thanks in advance. Please cc me; I'm not on the list.
Sincerely, Faheem Mitha.
************************************************************************
#include "lattice.hh"
#include "mh.hh"
#define MATHLIB_STANDALONE
#include <Rmath.h>
/* random sample from proposal distribution q-gibbs */
double q_gibbs_rand(Cube& cube, double& beta, vector<double>::size_type&
t)
{
vector<double> ctr = ((0.5)*(cube.down + cube.up)).coord;
vector<double>::size_type hsize = ctr.size();
double a, u, y;
if(t == 0)
a = beta*ctr[t+1];
else if(t == hsize - 1)
a = beta*ctr[t-1];
else
a = beta*(ctr[t-1] + ctr[t+1]);
GetRNGstate();
u = unif_rand();
PutRNGstate();
y = (1/a)*log( ( exp(a) - exp(-a) )*u + exp(-a) );
return y;
}
****************************************************************************
g++-3.0 -c -Wall -pedantic -Werror -g rand.cc -lRmath
In file included from rand.cc:4:
/usr/include/Rmath.h:520: declaration of `double log1p(double)' throws
different exceptions
/usr/include/bits/mathcalls.h:125: than previous declaration `double
log1p(double) throw ()'
rand.cc: In function `double q_gibbs_rand(Cube&, double&, size_t&)':
rand.cc:23: `GetRNGstate' undeclared (first use this function)
rand.cc:23: (Each undeclared identifier is reported only once for each
function
it appears in.)
rand.cc:25: `PutRNGstate' undeclared (first use this function)
make: *** [rand.o] Error 1
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list