We had a couple of questions regarding the external C++ functionality within RStan. Specifically, we want to determine the feasibility of calling an external static library or calling an external C++ header file with multiple functions from RStan. Additionally, we wanted to address a concern we encountered regarding using more than 4 parameters in our external C++ header file.
First, we would like to address the concern of using multiple variables within an external C++ file. When taking in more than 4 parameters using our external C++ header file, we run into the same errors that we encountered when trying to use PyStan. We have not tried ways to mitigate this issue such as packing/unpacking the variables using a tuple or simply limiting the parameters input from the RStan side of things. We simply wanted to note that it was an issue we encountered when attempting to fit the external C++ functionality of RStan to our problem.
Second, we would like to ask for advice regarding the use of an external function that is located within a static library (.a) file. When attempting to use a function within an external static library with the use of a C++ header file, we are unable to produce a functional Stan model. Unfortunately, we are unable to post the output from R when attempting to send data from RStan to an external C++ header file, which included and used a function from a static object. When we use the verbose argument, it shows 187 warnings and 15 errors, with most the warnings containing an excessive amount of machine code.
When attempting to bypass the C++ header file entirely and simply send the data directly to the static object file like so…
loadedStanModel <- stan_model(model_code = stanModel, allow_undefined = TRUE, verbose = TRUE, includes = paste0('\n#include "', file.path(getwd(), 'parabolaObject.a'), '"\n'))
… R produces the same output. As such, our first question: is it possible to use an external static library when using the external C++ functionality of RStan? Moreover, is it possible to use more than one external C++ file or object with RStan?
Third, in attempt to break down the problem of using an external static library with RStan, we simply included an additional function within the already working external C++ header file and tried using that. We simply broke down the one working function into two functions that theoretically accomplish the same task. One function would simply pass parameters initially input into the C++ header file to another function, which would return a result. However, this did not work.
Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! In file included from file5f2481e63e6.cpp:8:
17 warnings and 11 errors generated. make: *** [file5f2481e63e6.o] Error 1
Our second question: is it possible to use multiple functions within a single external C++ file in conjunction with RStan?
Thank you for any assistance you can offer.