-
-
Notifications
You must be signed in to change notification settings - Fork 373
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
Unexpected error when passing a multi-index to a offset or multiply constraint #3330
Comments
@SteveBronder It seems this was exposed by stan-dev/stanc3#1441 but I'm not sure. I'm also not sure if it would be considered a bug in the codegen or in the math library Could you take a look? |
When I run this locally I am getting an error that the multiplier is infinite at some values.
So looking at the code auto a_effect =
in__.template read_constrain_offset_multiplier<
Eigen::Matrix<local_scalar_t__,-1,1>, jacobian__>(0,
stan::model::rvalue(a_group_mu, "a_group_mu",
stan::model::index_multi(group_index_for_a)), lp__, n_a); Here template <typename T, typename M, typename S,
require_all_not_nonscalar_prim_or_rev_kernel_expression_t<
T, M, S>* = nullptr>
inline auto offset_multiplier_constrain(const T& x, const M& mu,
const S& sigma) {
const auto& mu_ref = to_ref(mu);
const auto& sigma_ref = to_ref(sigma);
if (is_matrix<T>::value && is_matrix<M>::value) {
check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
}
if (is_matrix<T>::value && is_matrix<S>::value) {
check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
} else if (is_matrix<M>::value && is_matrix<S>::value) {
check_matching_dims("offset_multiplier_constrain", "mu", mu, "sigma",
sigma);
}
check_finite("offset_multiplier_constrain", "offset", value_of_rec(mu_ref));
check_positive_finite("offset_multiplier_constrain", "multiplier",
value_of_rec(sigma_ref));
return fma(sigma_ref, x, mu_ref);
} template <typename T1, typename T2, typename T3,
require_any_matrix_t<T1, T2, T3>* = nullptr,
require_not_var_t<return_type_t<T1, T2, T3>>* = nullptr>
inline auto fma(T1&& x, T2&& y, T3&& z) {
if (is_matrix<T1>::value && is_matrix<T2>::value) {
check_matching_dims("fma", "x", x, "y", y);
}
if (is_matrix<T1>::value && is_matrix<T3>::value) {
check_matching_dims("fma", "x", x, "z", z);
} else if (is_matrix<T2>::value && is_matrix<T3>::value) {
check_matching_dims("fma", "y", y, "z", z);
}
return make_holder(
[](auto&& x, auto&& y, auto&& z) {
return ((as_array_or_scalar(x) * as_array_or_scalar(y))
+ as_array_or_scalar(z))
.matrix();
},
std::forward<T1>(x), std::forward<T2>(y), std::forward<T3>(z));
} I think what might be happening is that we are making an rvalue eigen expression here when making the multi index. stan::model::rvalue(a_group_mu, "a_group_mu",
stan::model::index_multi(group_index_for_a)) Then the |
Model and data:
When using
offset
, this prints:(note that the size is essentially random and changes each run!!)
When using
multiplier
as above, it simply segfaults inEigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>
, with the backtracesuggesting the issue is in write_array (meaning the prim overload of everything)
cc @mike-lawrence
The text was updated successfully, but these errors were encountered: