-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Tilde syntax does not properly generate promote_scalar for array arguments #1337
Comments
Unless I misunderstand the example, this is a feature: https://mc-stan.org/docs/reference-manual/calling-functions.html#argument-promotion I believe the implementation dates back to #1004 |
Interesting. It gave me a terrible error when I did this with the |
Here's the program that doesn't compile and gives c++ errors instead. Note the functions {
real multi_wallenius_integral(real t, // Function argument
real xc, array[] real theta, // parameters
array[] real x_r, // data (real)
array[] int x_i) {
// data (integer)
real Dinv = 1 / theta[1];
int Cp1 = num_elements(x_i);
int n = x_i[1];
real v = 1;
for (i in 2 : Cp1)
v *= pow(1 - t ^ (theta[i] * Dinv), x_i[i]);
return v;
}
real multi_wallenius_lpmf(data array[] int k, vector m, vector p, data array[] real x_r,
data real tol) {
int C = num_elements(m);
real D = dot_product(to_row_vector(p), (m - to_vector(k[2 : C + 1])));
real lp = log(integrate_1d(multi_wallenius_integral, 0, 1,
append_array({D}, to_array_1d(p)), x_r, k, tol));
for (i in 1 : C)
lp += -log1p(m[i]) - lbeta(m[i] - k[i + 1] + 1, k[i + 1] + 1);
return lp;
}
}
data {
int<lower=0> N;
int<lower=0> C;
array[N, C + 1] int y;
vector[C] m;
real tol;
}
transformed data {
array[0] real x_r;
array[0] int x_i;
}
parameters {
simplex[C] probs;
}
model {
for (i in 1:N)
y[i] ~ multi_wallenius(m, probs, x_i, tol);
} |
Interesting, it’s definitely possible there’s some missing edge cases with functions like that. I’ll try to investigate |
Huh, that seems like an edge case of the target += multi_wallenius_lpmf(y[i] | m, probs, x_i, tol); Fixes compilation, though it could still have a semantic bug depending on your intent. |
@spinkney Do I have your permission to include that example as a new regression test? I think I have the fix for this ready to go |
That was quick! Yes, please use that. |
This compiles in cmdstan version 2.32.2:
The text was updated successfully, but these errors were encountered: