Removed Features
This chapter lists functionalities that were once present in the language but have since been removed, along with how to replace them.
lp__
variable
Removed: The variable lp__
is no longer available for direct access or manipulation.
Replacement: General manipulation of the value of the lp__
variable is not allowed, but
lp__ <- lp__ + e;
can be replaced with
target += e;
The value of lp__
is available through the no-argument function target()
.
Assignment with <-
Removed: The operator <-
for assignment, e.g.,
a <- b;
is no longer available.
Replacement: The new syntax uses the operator =
for assignment, e.g.,
a = b;
Removed In: Stan 2.33
increment_log_prob
statement
Removed: The increment_log_prob(u)
statement for incrementing the log density accumulator by u
is no longer available.
Replacement: Replace the above statement with
target += u;
Removed In: Stan 2.33
get_lp()
function
Removed: The built-in no-argument function get_lp()
is no longer available.
Replacement: Use the no-argument function target()
instead.
Removed In: Stan 2.33
_log
density and mass functions
Removed: Formerly, the probability function for the distribution foo
would be applied to an outcome variable y
and sequence of zero or more parameters ...
to produce the expression foo_log(y, ...)
. This suffix is no longer a special value.
Replacement: If y
can be a real value (including vectors or matrices), replace
foo_log(y, ...)
with the log probability density function notation
foo_lpdf(y | ...).
If y
must be an integer (including arrays), instead replace
foo_log(y, ...
with the log probability mass function
foo_lpmf(y | ...).
Removed In: Stan 2.33
cdf_log
and ccdf_log
cumulative distribution functions
Removed: The log cumulative distribution and complementary cumulative distribution functions for a distribution foo
were formerly written as foo_cdf_log
and foo_ccdf_log
.
Replacement:
Replace foo_cdf_log(y, ...)
with foo_lcdf(y | ...)
.
Replace foo_ccdf_log(y, ...)
with foo_lccdf(y | ...)
.
User-defined function with _log
suffix
Removed: A user-defined function ending in _log
can be no longer be used in statements.qmd#distribution-statements.section.
Replacement: Replace the _log
suffix with _lpdf
for density functions or _lpmf
for mass functions in the user-defined function.
Removed In: Stan 2.33
Note: Following Stan 2.33, users can stil define a function ending in _log
, it simply no longer has a special meaning or is supported in the ~
syntax.
if_else
function
Removed: The function if_else
is no longer available.
Replacement: Use the conditional operator which allows more flexibility in the types of b
and c
and is much more efficient in that it only evaluates whichever of b
or c
is returned.
x = if_else(a, b, c);
with
x = a ? b : c;
Removed In: Stan 2.33
Character #
as comment prefix
Removed: The use of #
for line-based comments is no longer permitted. #
may only be used for #include
statements.
Replacement: Use a pair of forward slashes, //
, for line comments.
Removed In: Stan 2.33
Postfix brackets array syntax
Before Stan 2.26, arrays were declared by writing syntax after the variable.
Removed: The use of array declarations like
int n[5];
real a[3, 4];
real<lower=0> z[5, 4, 2];
vector[7] mu[3];
matrix[7, 2] mu[15, 12];
cholesky_factor_cov[5, 6] mu[2, 3, 4];
Replacement: The use of the array
keyword, which replaces the above examples with
array[5] int n;
array[3, 4] real a;
array[5, 4, 2] real<lower=0> z;
array[3] vector[7] mu;
array[15, 12] matrix[7, 2] mu;
array[2, 3, 4] cholesky_factor_cov[5, 6] mu;
Removed In: Stan 2.33
Nested multiple indexing in assignments
Stan interprets nested indexing in assingments as flat indexing so that a statement like
1] = b; a[:][
is the same as
1] = b; a[:,
However, this is inconsistent with multiple indexing rules.
To avoid confusion nested multiple indexing in assignment became an error in Stan 2.33. Nesting single indexing is still allowed as it cannot lead to ambiguity.
Removed In: Stan 2.33
Real values in conditionals
Removed: Using a real value in a conditional is no longer permitted.
real x = 1.0;
if (x) {
The value was interpreted as true if it is nonzero.
Replacement: For the exact equivalent, use a comparison operator to make the intent clear.
real x = 1.0;
if (x != 0) {
However, one should keep in mind that floating point calculations are subject to rounding errors and precise equality is fragile. It is worth considering whether the more robust alternative abs(x) < machine_precision()
is appropriate for the use case.
Removed In: Stan 2.34