How to declare row_vector array in function argument

This is a legal local declaration

row_vector[K] x[N];

How should you declare this as a function argument

real my_func(row_vector[] x[]){
real my_func(row_vector[] x[3]){
real my_func(row_vector[,] x){

none of these works.

real my_func(row_vector[] x)

I did that. But then

real num_visit = x[0];

fails.

Likely because Stan’s indexing starts at 1 rather than 0.

same failure for

real num_visit = x[1];

actually I would want
row_vector num_visit = x[1];

which also fails

even
row_vector[3] num_visit = x;

fails. that’s just a direct restatement.

What are the error messages saying? I’m guessing it didn’t compile?

It should be real num_visit = x[1][1].

Yes, that worked! thank you. I got it now.

You’ve declared an array of row vectors, so it’s just row_vector[] as a function type. There’s a full explanation in the manual section 6.4, “Unsized Argument Types”.

It can also be x[1, 1] if you prefer.

1 Like