Convert real to int



how can I convert a real to an int. I want to round

int x;
x = a * b;
where a and b and reals

Stan speed drastically decreases when adding one extra parameter

You can’t. Also, you don’t want to if a and b are unknown as it would mess up NUTS.


Are you trying to do some kind of interpolation problem? That’s the only example we’ve seen where this would be useful and not violate continuous differentiability for the posterior. But we’ve never gotten around to building in an interpolation.


Actually I wanted x to be the size of a new variable

real xx[x];


Could you use a work around like this:


Just keep in mind that the posterior should be continuously differentiable. You can write an inefficient linear function to truncate or a more efficient logarithmetic one with binary search, but however you do it, it’s going to break differentiability w.r.t. the integer.

You can also allocate things that are larger and only use some of them if it’s just a placeholder. But no way to get it the right size without hacking.