mrc-ide / odin

ᚩ A DSL for describing and solving differential equations in R
https://mrc-ide.github.io/odin
Other
106 stars 13 forks source link

Document return types of custom c functions #292

Open CGMossa opened 1 year ago

CGMossa commented 1 year ago

In order to circumvent #291, I decided to try to make a c-function, that takes a rectangular matrix, and performs some calculation on an array. But there must be a LHS to all lines; And thus I need a return type that means "2-d array" or even "1-D array".

Is it possible to know how this could look like? I've tried double* and double**, but that gave complaints.

CGMossa commented 1 year ago

I'm reopening this because I have a hard time figuring out what is allowed and not. In C, we cannot return arrays. An idea would be to use void c_function(size_t len, const double* input, double* output), but that doesn't work because odin expects a LHS to every line. I want to do an operation on a long array $M × 3$, and then use that to fill out vectors. But to do so, I'm expected to use i for the output vector $N ×1$. But then how can I perform the calculation on the former, store it, and then use its content on filling out N×1. if I just have a dummy <- c_function(...) it doesn't appear in the odin.c file generated, as in doesn't appear when things are happening.

CGMossa commented 1 year ago

It is as if I'm unable to pass a double** arr to a custom c-function..