On Friday, 7 July 2023 at 21:54:12 UTC, jmh530 wrote:

Cool.

The main thing I want to try is rstan. They have an interface called cmdstan that you can call from the command line that would be possible to use with D. The problem is that you have to write the data to a CSV file and then read it. So it would be kind of slow and I never got around to playing around with it in D. With your tool as it is, I would just have to copy the data in memory, which I would expect not to be as bad of an overhead as IO (but again haven't gotten around to do anything with it).

I just pushed an update with a minimal example of how to call RStan with the following workflow:

- Allocate a double[] in D and fill it with data.
- Use a custom allocator to pass a pointer to the double[] to R.
- Call RStan functions using the data.
- Pull the results into D.

Note that:

- This is the first I've used RStan. My previous (limited) usage of Stan was at the command line. In practice, you'd want to create a better interface, so that it feels like D rather than passing strings of code around. I'm not familiar enough with RStan to do that. - The custom allocator requires leaving 80 bits immediately preceding the data free for R to store its metadata related to the vector. There's no way around that as R would not know what to do without the metadata.

https://github.com/bachmeil/betterr/blob/main/testing/teststan.d

Reply via email to