What does `real[] a` mean?

Hello!

I was reading about data types and expression in STAN. I learned how to declare vectors, matrices, and arrays. For example:

int a is a scalar.
vector[2] is a column vector of lenght 2.
matrix[2,2] is a 2x2 matrix.
int a[1] is an array of 1 one integer.

but I’m still do not know what does real[] a mean or when to use. What it is? An array? Or is it same as real a?

I don’t think there are cases where you’d have empty brackets when declaring a variable, but they are used when indicating the return type of a function you’re defining in the functions block. For example:

functions {
  // return a real array containing x1 and x2
  real[] foo(real x1, real x2) {
    return {x1, x2};
  }
}

The use of real[] here indicates that the function will return an array of reals and not a scalar real.

5 Likes