Bug in abs?

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))

No matches for: 


Available argument signatures for abs:


  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.

[edit: escaped code with markdown]

Thanks for reporting.

It’s a bug in the doc, not the abs() function. We’ve deprecated abs() for real arguments, so we didn’t vectorize it. We can revisit abs and deprecate fabs, but last time we tried it led us a merry chase through compiler hell and we eventually gave up.

Also, you can use a declare-define syntax that’s easier to scan:

  vector[N] abs_y = fabs(y);

I created a next-manual issue issue comment so I’ll remember to fix it.

P.S. I edited your post to escape code. In general, you want to wrap in triple back ticks, like so:

my code here

Or you can just use <pre> tags to get it in typewriter font the way you rwrote it, but it won’t be highlighted.

I can just switch to fabs() and explain to the reader that this is short for “floating-point absolute value.”

Same for fmax and fmin. Like fabs(), these return real values even if given integer arguments. They’re built into C++.

abs() on the other hand is a pain because of legacy cruft from C99 namespaces and the new templates in C++11. We’ve never quite gotten it fully sorted, but then I think that’s because nobody’s devoted serious time to it.