Is there now a way to declare functions with inputs and outputs whose dimensions are determined by the data in the functions block? I saw this post from 2017 but don’t know if this is updated Global variable in functions block
As an example of why I’m trying to do this, here I declare new_array
(a size x
array of integers) and fill it with zeroes with a loop in transformed data
.
data{
int x;
}
transformed data{
array[x] int new_array;
for (i in 1:x) {
new_array[i] = 0;
}
}
I’m trying to turn the loop into a function fill_0s()
. The function would take an array of integers in_array
of arbitrary size and return an object the same size as in_array
. Here’s my attempt. The problem is that I’m using x
when declaring fill_0s()
but x
is not known until after the data are read in.
I’m guessing I could move the function to the transformed data
block but am wondering if it’s possible in the functions block, perhaps without declaring the size of the array that will be input/output.
functions{
array[x] int fill_0s(array[x] int in_array){
int z = size(in_array);
for (i in 1:z){
in_array[i] = 0;
}
return(in_array);
}
}
data{
int x;
}
transformed data{
array[x] int new_array;
new_array = fill_0s(new_array);
}