Skip to content

Error compiling rep_matrix inside of offset_multiplier_constrain #3146

@SteveBronder

Description

@SteveBronder

Compiling the following Stan code gives an error about bad return deduction

parameters {
  vector<lower=0>[5] sigma_gamma_n;
  matrix<multiplier=rep_matrix(sigma_gamma_n', 10)>[10, 5] z_gamma_n;
}

The error log is below which traces down into multiply_log about an inconsistent deduction for the return type. I think just adding constexpr if in this statement would fix this. Though I'd look to look at why the return types are just slightly different. That looks like a bug in type deduction

stan/lib/stan_math/stan/math/rev/fun/multiply_log.hpp:214:29: error: inconsistent deduction for auto return type: ‘stan::math::var_value<Eigen::Matrix<double, -1, -1, 1, -1, -1>, void>’ and then ‘stan::math::var_value<Eigen::Matrix<double, -1, -1> >’
  214 |     return make_callback_var(
      |            ~~~~~~~~~~~~~~~~~^
  215 |         multiply_log(arena_a.val(), arena_b),
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  216 |         [arena_a, arena_b](const auto& res) mutable {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 |           arena_a.adj()
      |           ~~~~~~~~~~~~~      
  218 |               += (res.adj().array() * arena_b.val().array().log()).sum();

https://gist.github.com/SteveBronder/5ba8b98ce92e7d1965fcce5a9fc091a2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions