Hi all. I had a problem with the abs function. I tried to apply it to a vector and I got an error. But in the Stan manual (page 431 of the Stan 2.17.0 manual), it says that abs works for any argument type. So I think it may be a bug.
Below is the Stan code (I wrote up a very simple example to demonstrate the point), followed by the error message.
data {
int N;
vector[N] y;
}
transformed data {
vector[N] abs_y;
abs_y = abs(y);
}
parameters {
real theta;
}
model {
y ~ normal(theta, 1);
}
In R:
> stan("abs_test.stan", data=list(N=5, y=1:5))
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
abs(vector)
Available argument signatures for abs:
abs(int)
abs(real)
error in 'model132ff5d06821b_abs_test' at line 7, column 17
-------------------------------------------------
5: transformed data {
6: vector[N] abs_y;
7: abs_y = abs(y);
^
8: }
-------------------------------------------------
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model 'abs_test' due to the above error.
When I altered the model, changing “abs” to “fabs”, it worked fine.
Thanks for the help.
Andrew
[edit: escaped code with markdown]