I’m trying to get the hang of the new reduce_sum parallelization in cmdstanr, and I’m getting what is probably a very basic error that I can’t seem to crack. I’m just trying to run a very simple OLS with 2 predictors–no hierarchical structure, no non-linear effects–as a proof of concept before I start building in anything fancy. But I keep getting an “incompatible type” error with reduce_sum. The problem is definitely in the code–it doesn’t even map to real data yet. (I can get it to compile just fine if I remove the reduce_sum functionality.)
The code is
functions {
real partial_sum(vector slice_Y,
int start, int end,
matrix X,
real alpha,
vector beta,
real sigma) {
return normal_id_glm_lpdf(slice_Y | X[start:end], alpha, beta, sigma);
}
}
data {
int<lower=0> N;
vector[N] Y;
matrix[N,2] X;
int<lower=1> grainsize;
}
parameters {
real alpha;
vector[2] beta;
real sigma;
}
model {
alpha ~ normal(0,10);
beta[1] ~ normal(0, 10);
beta[2] ~ normal(0, 10);
target += reduce_sum(partial_sum, grainsize, Y,
X, alpha, beta, sigma);
}
and the error message is:
Semantic error in '/var/folders/b_/hwc8hm2n6sq1twhhg4jv53_w0000gp/T/RtmpBGz51k/model-161ea232bb1c1.stan', line 28, column 12 to line 29, column 45:
-------------------------------------------------
26: beta[2] ~ normal(0, 10);
27:
28: target += reduce_sum(partial_sum, grainsize, Y,
^
29: X, alpha, beta, sigma);
30: }
-------------------------------------------------
Ill-typed arguments supplied to function 'reduce_sum'. Available arguments:
(T[], int, int, ...) => real, T[], int, ...
(T[,], int, int, ...) => real, T[,], int, ...
(T[,,], int, int, ...) => real, T[,,], int, ...
(T[,,,], int, int, ...) => real, T[,,,], int, ...
(T[,,,,], int, int, ...) => real, T[,,,,], int, ...
(T[,,,,,], int, int, ...) => real, T[,,,,,], int, ...
(T[,,,,,,], int, int, ...) => real, T[,,,,,,], int, ...
Where T is any one of int, real, vector, row_vector or matrix.
Instead supplied arguments of incompatible type: (vector, int, int, matrix, real, vector, real) => real, int, vector, matrix, real, vector, real
make: *** [/var/folders/b_/hwc8hm2n6sq1twhhg4jv53_w0000gp/T/RtmpBGz51k/model-161ea232bb1c1.hpp] Error 1
Error: An error occured during compilation! See the message above for more information.
Any help would be greatly appreciated. I ultimately have some much more complex models running on large data sets that I’m hoping would benefit from the within-chain parallelization of reduce_sum. Thanks!