Hey all,
So after shifting from PyStan to RStan, @bfinley and I have been working on an RScript and .hpp file that would work for our use case. Unfortunately, we have ran into an issue. When using the RScript along with the .hpp file we created, I receive the following error output on my MacOS (Catalina) system:
> loadedStanModel <- stan_model(model_code = stanModel, allow_undefined = TRUE,
+ includes = paste0('\n#include "',
+ file.path(getwd(), 'external_parabola.hpp'), '"\n'))
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Core:535:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:10:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
#pragma clang diagnostic pop
^
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
In file included from /Library/Frameworks/R.framework/Versions/
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file281d95ecc81.cpp 2> file281d95ecc81.cpp.err.txt' had status 1
Error in sink(type = "output") : invalid connection
However, when @bfinley runs the same RScript along with the same .hpp file, RStan produces the expected output:
Here is the RScript code:
setwd("/Users/matt/Desktop/School/Capstone_Project/RStan")
library(limma)
library(rstan)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
stanModel =
"
functions {
real parabola_function(real A, real B, real C, real X);
#include external_parabola.hpp
}
data {
int J;
int I;
real X[J,I];
real Y[J,I];
}
parameters {
real A;
real B;
real C;
real<lower=0> sigma;
}
transformed parameters {
real y_hat = parabola_function(A, B, C, X[J,I]);
}
model {
Y[J,I] ~ normal(y_hat, sigma);
}
"
x_data = read.columns("parabola_data.csv", c("x"), sep = ",")
y_data = read.columns("parabola_data.csv", c("y"), sep = ",")
parabola_data <- list(J = 40, I = 1, X = x_data, Y = y_data)
# try(readLines(stanc(model_code = stanModel, allow_undefined = TRUE)$cppcode))
loadedStanModel <- stan_model(model_code = stanModel, allow_undefined = TRUE,
includes = paste0('\n#include "',
file.path(getwd(), 'external_parabola.hpp'), '"\n'))
fit <- sampling(loadedStanModel, data = parabola_data, iter=1000, chains=1,
sample_file='output.csv', control = list(max_treedepth = 10, adapt_delta = 0.99))
print(fit)
And here is the .hpp code:
real parabola_function(real A, real B, real C, real X)
{
return A*X*X+B*X+C;
}
Can someone help me diagnose this issue?
Thank you,
Matt