Skip to content

Commit

Permalink
Remove usages of fabs
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Aug 15, 2023
1 parent 98d13f5 commit 381b625
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
7 changes: 0 additions & 7 deletions src/functions-reference/real-valued_basic_functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,6 @@ of those types, `abs` returns the same type where each element has had its
absolute value taken.
`r since("2.0, vectorized in 2.30")`

<!-- R; fabs; (T x); -->
\index{{\tt \bfseries fabs }!{\tt (T x): R}|hyperpage}

`R` **`fabs`**`(T x)`<br>\newline
absolute value of x
`r since("2.0, vectorized in 2.13, deprecated in 2.30, scheduled for removal in 2.33")`

<!-- real; fdim; (real x, real y); -->
\index{{\tt \bfseries fdim }!{\tt (real x, real y): real}|hyperpage}

Expand Down
2 changes: 1 addition & 1 deletion src/reference-manual/statements.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ definitions. For the case above, the following adjustment will
account for the log transform.^[Because $\log | \frac{d}{dy} \log y | = \log | 1/y | = - \log |y|$.]

```stan
target += - log(fabs(y));
target += - log(abs(y));
```


Expand Down
8 changes: 4 additions & 4 deletions src/stan-users-guide/custom-probability.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ parameters {
real<lower=-1, upper=1> y;
}
model {
target += log1m(fabs(y));
target += log1m(abs(y));
}
```

The single scalar parameter `y` is declared as lying in the
interval `(-1,1)`. The total log probability is
incremented with the joint log probability of all parameters, i.e.,
$\log \mathsf{Triangle}(y \mid -1,1)$. This value is coded in Stan as
`log1m(fabs(y))`. The function `log1m` is defined so
`log1m(abs(y))`. The function `log1m` is defined so
that `log1m(x)` has the same value as $\log(1-x)$, but the
computation is faster, more accurate, and more stable.

Expand All @@ -64,7 +64,7 @@ $\mathbb{R}$ as follows by defining the probability to be `log(0.0)`,
i.e., $-\infty$, for values outside of $(-1,1)$.

```stan
target += log(fmax(0.0,1 - fabs(y)));
target += log(fmax(0.0,1 - abs(y)));
```

With the constraint on `y` in place, this is just a less
Expand Down Expand Up @@ -137,7 +137,7 @@ The following Stan program implements this function,
```stan
real binormal_cdf(real z1, real z2, real rho) {
if (z1 != 0 || z2 != 0) {
real denom = fabs(rho) < 1.0 ? sqrt((1 + rho) * (1 - rho))
real denom = abs(rho) < 1.0 ? sqrt((1 + rho) * (1 - rho))
: not_a_number();
real a1 = (z2 / z1 - rho) / denom;
real a2 = (z1 / z2 - rho) / denom;
Expand Down
2 changes: 1 addition & 1 deletion src/stan-users-guide/reparameterization.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ transformed parameters {
matrix[K, K] J; // Jacobian matrix of transform
// ... compute v as a function of u ...
// ... compute J[m, n] = d.v[m] / d.u[n] ...
target += log(fabs(determinant(J)));
target += log(abs(determinant(J)));
// ...
}
model {
Expand Down
4 changes: 2 additions & 2 deletions src/stan-users-guide/simulation-based-calibration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ parameters.
```stan
transformed data {
real mu_sim = normal_rng(0, 5);
real tau_sim = fabs(normal_rng(0, 5));
real tau_sim = abs(normal_rng(0, 5));
int<lower=0> J = 8;
array[J] real theta_sim = normal_rng(rep_vector(mu_sim, J), tau_sim);
array[J] real<lower=0> sigma = fabs(normal_rng(rep_vector(0, J), 5));
array[J] real<lower=0> sigma = abs(normal_rng(rep_vector(0, J), 5));
array[J] real y = normal_rng(theta_sim, sigma);
}
parameters {
Expand Down
4 changes: 2 additions & 2 deletions src/stan-users-guide/user-functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ functions {
real relative_diff(real x, real y) {
real abs_diff;
real avg_scale;
abs_diff = fabs(x - y);
avg_scale = (fabs(x) + fabs(y)) / 2;
abs_diff = abs(x - y);
avg_scale = (abs(x) + abs(y)) / 2;
return abs_diff / avg_scale;
}
}
Expand Down

0 comments on commit 381b625

Please sign in to comment.