Passing an array [] simplex to a function?

hello

I am attempting to pass an array [] simplex to a function. When i do this, i get the following compile error:

 -------------------------------------------------
    14:      int ii, int nt, int idx, int k,
    15:      real rho_delta, real rho_psi, vector ba1, vector ba2, 
    16:      array [] simplex bs1, array [] simplex bs2,
                      ^
    17:      matrix d, matrix p, array [] int vt,
    18:      vector item_available) {
   -------------------------------------------------

Expected non-array type after "array" declaration.

Changing the function so that it is looking for array [] vector appears to fix this.

I was just wondering if this is the proper solution, or am I missing something.

Thanks

1 Like

vector is the correct specification here. Constrained types cannot be declared as inputs or outputs in functions.

4 Likes

Thanks for flagging this – we can definitely do better on this error message. After this PR is merged, the next version will print this instead:

   -------------------------------------------------
     1:  functions {
     2:    void foo(array[] simplex x) {}
                            ^
     3:  }
   -------------------------------------------------

Ill-formed type. Expected an unconstrained, non-array type after "array" declaration.
  For example, this means a type like "matrix", not "corr_matrix" or "matrix[3,4]".
  See the complete table of types at:
  https://mc-stan.org/docs/reference-manual/types.html#variable-declaration.section
3 Likes