# Integer arguments (not data) into Map-reduce function

In the recent STAN manual, the following function “bl_glm” (in page 284) is an argument of the function “sum(map_rect(bl_glm, append_row(mu, sigma), beta, x_r, x_i))” (in page 285).

functions {
vector bl_glm(vector mu_sigma, vector beta,
real[] x, int[] y) {
vector[2] mu = mu_sigma[1:2];
vector[2] sigma = mu_sigma[3:4];
real lp = normal_lpdf(beta | mu, sigma);
real ll = bernoulli_logit_lpmf(y | beta[1] + beta[2] * to_vector(x));
return [lp + ll]’;
} }

Is there a way to replace the hard coded integer 1,2,3,4 into integers that can be set from outside? For example,

functions {
vector bl_glm(vector mu_sigma, vector beta,
real[] x, int[] y) {
vector[K] mu = mu_sigma[1:K];
vector[K] sigma = mu_sigma[(K+1):(K*2)];
real lp = normal_lpdf(beta | mu, sigma);
real ll = bernoulli_logit_lpmf(y | beta[1] + beta[2] * to_vector(x));
return [lp + ll]’;
} }

How to input the integer K? I can only think of a cumbersome way–to let the integer data y to be a vector with all elements being K, which consumes unnecessarily large storage.

By the way, if there are thousands of samples. Is map-reduce function significantly faster than for loop w.r.t. each sample?

Thank you.