# Compilation error in one dimensional integration in Rstan

#6

msgs is the print stream for error messages.

What happens if you use

 double Q = stan::math::integrate_1d(f2, ll_new, ul_new, {beta,M0}, {},{}, std::ostream msgs)


or even

 double Q = stan::math::integrate_1d(f2, ll_new, ul_new, {beta,M0}, {},{}, NULL)


#7

Hi @increasechief, I tried both but gave me same error. However, if I use the following code in my header file; I get no compilation error but it shows error in loading object as Symbol not found. The code in the header file which shows NO COMPILATION error (but some warnings):

template <typename T0__, typename T1__,typename T2__>
typename boost::math::tools::promote_args<T0__, T1__, T2__>::type
test1(const T0__& ll, const T1__& ul,const T2__& beta, const T2__& M0, std::ostream& msgs) {

auto f2= [&](double& x, double& xc,  std::vector<double>& theta, std::vector<double>& x_r, std::vector<int>& x_i,  std::ostream& msgs) {
return std::exp(- theta[0]*(x-theta[1]));
};

double ll_new=ll;
double ul_new=ul;
double betan= beta;
double M0n= M0;

double Q = stan::math::integrate_1d(f2, ll_new, ul_new, {betan,M0n}, {},{}, msgs);
return Q;
}


But the error is:

Error in dyn.load(libLFile) :
unable to load shared object '/var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/file235821cc62f3.so':
Referenced from: /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/file235821cc62f3.so
Expected in: flat namespace
in /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/file235821cc62f3.so


#8

I already told you to use *pstream__.

I’m not quite sure why that is. I would suggest, though, that in your definition for f2 that you replace double & x with double x, double & xc with double xc, and std::vector<double>& with const std::vector<double>&. Whether or not that would help isn’t clear to me, but it’s worth a shot.

Also, what do you know about C++? It doesn’t look like you’re familiar with it, and C++ can be a rather unforgiving and treacherous language even for those who are familiar with it.

#9

Hi, Using the corrections (*pstream__, double x, double xc, const std::vector) did not help me. I still get the same error. However, if you see my previous comment; if I use that code; I do not get any compilation error but I get error for loading object.

#10

Yes, here the function test1 passes the message stream.

For the rest of the error Google provided me with this: https://github.com/stan-dev/rstan/issues/448

#11

Hi @jjramsey; ignore my previous reply. I tried your code again, this time I did not get compilation error but I get this error:

Error in dyn.load(libLFile) :
unable to load shared object '/var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/file2358332bd675.so':
Referenced from: /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/file2358332bd675.so
Expected in: flat namespace
in /var/folders/4w/v4pl36r9475cb2fkspc3qxkm0000gp/T//RtmpYMEu3o/file2358332bd675.so


. Could you tell me how to resolve this?

#12

Hi, do you know how to unload older DLLs?

#13

#14

But in my case, the error message is: SYMBOL NOT FOUND. I do not understand which symbol did they not find. And how to resolve this

#15

It is telling you it cannot find a function specialization for

boost::math::tools::promote_args<double, double, stan::math::var, double, float, float>::type
model*_namespace::test1<double, double, stan::math::var, double>(
double const&, double const&, stan::math::var const&, double const&, std::basic_ostream<char, std::char_traits<char> >*
)


I believe this is because you are returning a double for Q even though it should be of type stan::math::var if any of the arguments to the function is of type stan::math::var.

Perhaps more importantly why are you doing numerical integration of e^{-\theta_0 \left(x - \theta_1\right)}, which has an analytical solution?

#16

Just to test if I can really export external C++ function; before applying it on a much complicated model. So it’s a test case for me

#17

The integrate_1d function got merged into the Stan language today, so you might as well just install the development versions of stuff with

source("https://raw.githubusercontent.com/stan-dev/rstan/develop/StanHeaders/install-github.R", echo = TRUE)
remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")


and then do like

1d integration in STAN language--timeline?
#18

I get

Error: package or namespace load failed for ‘rstan’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/u/77/ave/unix/R/x86_64-pc-linux-gnu-library/3.5/rstan/libs/rstan.so':
/u/77/ave/unix/R/x86_64-pc-linux-gnu-library/3.5/rstan/libs/rstan.so: undefined symbol: _ZNK4stan4lang14local_var_type10array_lensEv
Execution halted


I’ve tried some other ways to install, too, but with the same error (or with _ZNK4stan4lang14base_expr_type11is_int_typeEv) and I haven’t been able to figure out how to fix this.

#19

Which compiler are you using?

#20

% g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright © 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

#21

It’s the same for me on g++ (Debian 8.3.0-2) 8.3.0.

#22

Try again

#23

Didn’t change anything…

#24

Once again

#25

Thanks, now it works! I was going to check if I can get the vi diagnostic to RStan (already works with CmdStan), but need to continue with that tomorrow.