I am having trouble writing a user-defined function. Here is such a function that does work:
functions{
array[,] real foo(real mu, real sigma){
array[2,2] real v;
v[1,1] = sigma + mu;;
v[1,2] = sigma - mu;
v[2,1] = sigma^2;
v[2,2] = mu^2;
return v;
}
}
When I run this using rstan::expose_stan_functions
I get, correctly
` foo(mu = 2, sigma = 5)
[[1]]
[1] 7 3
[[2]]
[1] 25 4
But if I add a line
real<lower = 0> A;`
functions{
array[,] real foo(real mu, real sigma){
array[2,2] real v;
real<lower = 0> A;
A = sigma + mu;
v[1,1] = A;
v[1,2] = sigma - mu;
v[2,1] = sigma^2;
v[2,2] = mu^2;
A = sum(v)
return v;
}
}
I get the error:
Identifier expected after sized type in local (or model block) variable declaration. (No transformations/constraints allowed.)
I find the error message incomprehensible. Can someone tell me what I am doing wrong? Thanks.