Rcpp Code chrashes after updating Rcpp from 1.0.6 to 1.0.7 - rcpp

I'm using a self-written model in Rcpp which works fine when using Rcpp 1.0.6 or 1.0.5. But after updating to Rcpp 1.0.7 the model run crashes right after executing the R function to start the model. (However, compilation with sourceCpp() works without any error or warning.)
The code in Rcpp is organized as follows: there are several functions written in different c++-files and these functions are loaded with header files into my runModel.cpp file that defines my function that is exported to R to run the code.
This function is used like this runModel(DateVector SimPeriod, List ModelInput, NumericVector Settings). Maybe it is worth noting that functions in different c++-files are using the same variables and changing them sometimes, so I had to write also something like initModel.cpp and a correspondent header file which is imported in almost every c++ files.
I was already looking in the https://cran.r-project.org/web/packages/Rcpp/news.html to relate the made changes in 1.0.7 to my issue. But unfortunately, I have no idea what might be the reason for the crash. I'm appreciating every comment on this.
I'm sorry that I cannot give a reproducible example but the model code is too complex to create one (especially because I do not know where the error is hidden.)

Related

Can JAGS (Just Another Gibbs Sampler) deal with ordinary differential equations?

I searched about the JAGS's manual and one post (here in 2012) about the ordinary differential equation (ode). I was thinking JAGS can because it's similar to WinBUGS (which does it through WBdiff interface). However, if I let JAGS read in my ode code, it cannot even recognize the D(y[...], t) expression.
Can JAGS deal with ode? Maybe I missed a plug-in in JAGS like WBdiff?
While WinBUGS/OpenBUGS/JAGS have almost equivalent syntax/feature sets, there are a few differences between them: one of these is that there is no ODE solver included as part of a standard JAGS installation.
However, JAGS is extensible using user-specified modules (like the plug-ins you mentioned), which provide new functions/distributions using C++ code that can then be used within JAGS when that module is loaded. It would certainly be possible to implement an ODE this way using e.g. the ODE solvers included in the boost C++ library. To do so you will need the following:
Familiarity with C++
Instructions for how to build a module for JAGS
I can't help you with the former, so this may be a dead-end for you if you have never used C++ before. But there is a tutorial available for how to build a JAGS module: https://pubmed.ncbi.nlm.nih.gov/23959766/ This article shows how to build a standalone module, but if you are happy to accept the limitation of using JAGS from R (as most people do) then it is MUCH easier to build a JAGS module within an R package - you could follow code in the runjags package as an example https://cran.r-project.org/package=runjags
If you are thinking of trying to do this yourself then I could potentially help with a few pointers along the way. Of course, it is also possible that someone else has already done this, but if so then I am not aware of it.

Clang++: Use AddressSanitizer for small portion of library

I am working on a quite large code base and some snippets I added are causing weird memory behaviour so I considered using the -fsanitize=address option for clang++.
However it seems I cannot make it compile the whole library, because of a whole bunch of errors caused by the linker.
I am not really aware of the inner workings of the AddressSanitizer, but is it generally possible to apply it only to a small portion of a library's code base (let's say to a single header) and if so how?

Is there a way to use the deap library in grasshopper

Is there a way I can use the deap library inside grasshopper's Python node
I want to run a genetic algorithm but the fitness function is to be calculated by grasshopper (only the fitness function, all the other things are to be taken of by deap inside the python node)
can it be done?
I am having problem with
importing the deap library in grasshopper's Python interface(I think I will be able to solve it by copying the files manually from Python path)
(major problem) grashopper doesn't allow closed loops so I cant seem to find a way to feed the fitness back into the Python node with the main code
couldnt get it to work, had to make do with the grasshopper pluggins
the problem was that you can only install iron python libraries for grasshopper
These are two well known issues with 'out-of-the-box' grasshopper but there are several plugins that can help overcome them.
Question One
The basic GHPython component uses Iron Python and can limit which libraries are compatible and able to be used. To get around this constraint there is a plugin called 'GH_CPython'. It allows you to set a locally installed python interpreter for your code, and then have access to any libraries available to that local interpreter. So if you install deap Libary locally then it will be available within the grasshopper GH_Cpython editor. Here is a link to download and install GH_CPython: https://www.food4rhino.com/en/app/ghcpython
Question Two
As you noted, Grasshopper is procedural and has limited support for recursive routines. To get around this there are several plugins that support recursion and may be able to help with your implementation. Which plugin would be best for your situation is difficult to say without a deeper description of your goals. Here are several options, each option provides recursive functionality that would allow for 'closed loops' where results of a script can be fed back as input.
Hoopsnake - very basic and has been around the longest
Anemone - A little more flexible and uses multiple components for loop start and end for cleaner-looking scripts. It also has a 'record history' functionality.
Octopus - Has a 'Loop' component that is similar to Hoopsnake. It also has a 'record history' functionality.

Theano : Can we reuse compile files generated by theano?

Uisng compile, Theano generates C++ code along with Cuda code and compiled lib.
Can we reuse those ones after ?
You could load them as a python module from the cache or just copy the code somewhere else and modify it to have a friendlier name.
Also there is a project to have Theano produce a some C code for a library that I know works for some situations but has never really been finished. If you are interested in that I would ask on the theano-dev mailing list.

Customising Cabal libraries (I think?)

Perhaps it's just better to describe my problem.
I'm developing a Haskell library. But part of the library is written in C, and another part actually in raw LLVM. To actually get GHC to spit out the code I want I have to follow this process:
Run ghc -emit-llvm on both the code that uses the Haskell module and the "Main" module.
Run clang -emit-llvm on the C file
Now I've got three .ll files from above. I add the part of the library I've handwritten in raw LLVM and llvm-link these into one .ll file.
I then run LLVM's opt on the linked file.
Lastly, I feed the LLVM bitcode fileback into GHC (which pleasantly accepts it) and produces an executable.
This process (with appropriate optimisation settings of course) seems to be the only way I can inline code from C, removing the function call overhead. Since many of these C functions are very small this is significant.
Anyway, I want to be able to distribute the library and for users to be able to use it as painlessly as possible, whilst still gaining the optimisations from the process above. I understand it's going to be a bit more of a pain than an ordinary library (for example, you're forced to compile via LLVM) but as painlessly as possible is what I'm looking for advice for.
Any guidance will be appreciated, I don't expect a step by step answer because I think it will be complex, but just some ideas would be helpful.

Resources