Problem with Syntax of arrays

I am not completely used to the syntax required yet, so this might be a trivial question. I want to introduce a function I need for my model, in which I sum over the product between <a|C|a> (a is a vector and C an array of matrices) and an array of vectors (legendre). My intention was to select one of the matrices from the array of matrices and one of the vectors from the array of vectors and then sum over those products.

functions {
    vector sum_abc(real N, real N_i, vector a, vector b, matrix[N] C_r, 
    matrix[N] C_i, vector[N] legendre){
        vector[N_i] sum_over;
        real intermediate;
        sum_over = 0;
        for n in(1:N){
            intermediate = a' * C_r[n] * a + b' * C_r[n] * b;
            intermediate += b' * C_i[n] * a - a' * C_i[n] * b;
            sum_over += intermediate * legendre[n];
        return sum_over;

The error I am getting is the following.

RuntimeError: Exception while compiling program_code: ValueError('Syntax error in \'/tmp/httpstan_fnnyv8zo/model_hunv7ya4.stan\', line 3, column 64 to column 65, parsing error:\n -------------------------------------------------\n 1: \n 2: functions {\n 3: vector sum_abc(real N, real N_i, vector a, vector b, matrix[N] C_r, \n ^\n 4: matrix[N] C_i, vector[N] legendre){\n 5: vector[N_i] sum_over;\n -------------------------------------------------\n\n"[" (list of commas) "]" expected in unsized return type of function definition.')

I am unsure what I am doing wrong.

What stands out initially are the definitions of the input matrices:

matrix[N] C_r
matrix[N] C_i

Matrices in stan need to be defined with the row and column:

matrix[R1,C1] C_r
matrix[R2,C2] C_i

If you want to declare an array of matrices, of length N, then you specify:

matrix[R1,C1] C_r[N]
matrix[R2,C2] C_i[N]

Thank you very much for your reply.
I was under the impression that if those matrices are declared in the data block and then passed in the final model block it would be declared properly.
Also in the User’s guide I found that for user defined functions one does not need to specify the dimensions of the passed vectors and matrices.

And that one only needs to pass brackets to declare the form of the arrays.

For anyone interested.
The issue turned to be the result of me specifying the exact lengths of the arrays in the function declaration.
In the user defined function block those arguments would have to declared as “matrix[ ] C_r”, “matrix[ ] C_i” and “vector[ ] legendre”, as the argument block for user defined functions only allows the declaration of the number of dimensions of the array.