stan-dev/stanc3

[BUG] Inline matrix construction fails to promote with mixed types

andrjohns opened this issue · 0 comments

The following model fails to compile:

data {
  real y_mean;
}

parameters {
  real y;
}

transformed parameters {
  matrix[2, 2] M;
  M = [[1, 2], [3, y]];
}

model {
  y ~ normal(y_mean, 1);
}

With the error:

/Users/andrew/.cmdstan/cmdstan-2.31.0/stan/lib/stan_math/lib/eigen_3.3.9/Eigen/src/Core/functors/AssignmentFunctors.h:24:104: error: assigning to 'double' from incompatible type 'const stan::math::var_value<double>'

Because the construction of M is transpiling to:

      stan::model::assign(M, stan::math::to_matrix(
        std::vector<Eigen::Matrix<double, 1, -1>>{
        (Eigen::Matrix<double,1,-1>(2) << 1, 2).finished(),
        (Eigen::Matrix<local_scalar_t__,1,-1>(2) << 3, y).finished()}),
        "assigning variable M");

Where the std::vector<Eigen::Matrix<double, 1, -1>> should more likely be std::vector<Eigen::Matrix<local_scalar_t__, 1, -1>>