-
-
Notifications
You must be signed in to change notification settings - Fork 198
Fix no instance of overloaded function stan::math::Holder::coeffRef
#2632
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
Conversation
```c++
R/library/StanHeaders/include/stan/math/prim/fun/scalar_seq_view.hpp(32): error: no instance of overloaded function "stan::math::Holder<ArgType, Ptrs...>::coeffRef [with ArgType=Eigen::ArrayWrapper<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>, Ptrs=<std::remove_reference_t<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0,
Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>>]" matches the argument list and object (the object has cv-qualifiers that prevent a match)
argument types are: (size_t)
object type is: const stan::ref_type_t<stan::math::Holder<Eigen::ArrayWrapper<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>, std::remove_reference_t<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>> &&>
inline auto operator[](size_t i) const { return c_.coeffRef(i); }
^
R/library/RcppEigen/include/Eigen/src/Core/ArrayBase.h(70): note: this candidate was rejected because mismatch in count of arguments
using Base::coeffRef;
^
R/library/RcppEigen/include/Eigen/src/Core/ArrayBase.h(70): note: this candidate was rejected because the selector is mismatched
using Base::coeffRef;
^
detected during:
instantiation of "auto stan::scalar_seq_view<C, stan::require_eigen_vector_t<C>>::operator[](size_t={unsigned long}) const [with C=stan::ref_type_t<stan::math::Holder<Eigen::ArrayWrapper<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>, std::remove_reference_t<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>,
std::remove_reference_t<std::vector<double, std::allocator<double>>>>>> &&>]" at line 87 of "R/library/StanHeaders/include/stan/math/prim/prob/gamma_lpdf.hpp"
instantiation of "stan::return_type_t<T_y, T_shape, T_inv_scale> stan::math::gamma_lpdf<propto,T_y,T_shape,T_inv_scale,<unnamed>>(const T_y &, const T_shape &, const T_inv_scale &) [with propto=false, T_y=std::vector<stan::math::var_value<double, void>, std::allocator<stan::math::var_value<double, void>>>, T_shape=double, T_inv_scale=double, <unnamed>=(void *)nullptr]" at line 1547 of "stan_files/polr.hpp"
instantiation of "stan::scalar_type_t<VecR> model_polr_namespace::model_polr::log_prob_impl<propto__,jacobian__,VecR,VecI,<unnamed>,<unnamed>>(VecR &, VecI &, std::ostream *) const [with propto__=false, jacobian__=false, VecR=Eigen::Matrix<stan::math::var, -1, 1, 0, -1, 1>, VecI=Eigen::Matrix<int, -1, 1, 0, -1, 1>, <unnamed>=(void *)nullptr, <unnamed>=(void *)nullptr]" at line 2116 of "stan_files/polr.hpp"
instantiation of "T_ model_polr_namespace::model_polr::log_prob<propto__,jacobian__,T_>(Eigen::Matrix<T_, -1, 1, 0, -1, 1> &, std::ostream *) const [with propto__=false, jacobian__=false, T_=stan::math::var]" at line 96 of "R/library/StanHeaders/include/src/stan/model/model_base_crtp.hpp"
instantiation of "stan::math::var stan::model::model_base_crtp<M>::log_prob(Eigen::Matrix<stan::math::var, -1, 1, 0, -1, 1> &, std::ostream *) const [with M=model_polr_namespace::model_polr]"
```
|
Do we have any idea why does this pop up with rstanarm and not our unit tests in Math? |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
No sure, but either it hits a condition that isn't tested in Math (template, argument type, ... etc.) or a different version of the headers (e.g., Eigen or other dependencies) in the R environment. It isn't good for the unit tests here that the checks have passed with and without this PR. I want @SteveBronder to review it; it might be a side effect of fc7dc24 or one of the reverts after it. It could also flag that a change is required in |
|
Thanks! Yeah once we figure out the details we definitely want a unit test in Math to prevent the same issue in the future. |
|
I think the issue here was just that |
Thanks @SteveBronder! I'll test your changes and get back to you if I run into any related issues. |
It was compiling successfully before your commit, and now it fails at line 42 with a similar error: R/library/StanHeaders/include/stan/math/prim/fun/scalar_seq_view.hpp(42): error: no instance of overloaded function "stan::math::Holder<ArgType, Ptrs...>::coeffRef [with ArgType=Eigen::ArrayWrapper<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>, Ptrs=<std::remove_reference_t<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0,
Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>>]" matches the argument list and object (the object has cv-qualifiers that prevent a match)
argument types are: (size_t)
object type is: const stan::ref_type_t<stan::math::Holder<Eigen::ArrayWrapper<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>, std::remove_reference_t<stan::math::Holder<Eigen::Map<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0>>, std::remove_reference_t<std::vector<double, std::allocator<double>>>>>> &&>
return c_.coeffRef(i);
^ |
|
@SteveBronder I've to revert your last commit to fix the new error. Feel free to make any changes, and I'll test them. |
This reverts commit bf6e4fd.
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
|
@hsbadr are you able to make a minimal stan model that shows this? I looked at the data {
real<lower=0> shape;
real<lower=0> rate;
}
parameters {
real<lower=0> alpha[8];
}
model {
target += gamma_lpdf(alpha | shape, rate);
}Are you using the develop version of Stan math? This sounds like it might be some systemic error with how we handle const in the math library I'd just like to make sure we catch this now before we end up doing a bunch of little patches here and there that get around some underlying problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to know the underlying issue but also I think this is good if it's delaying anything else rn
Yes, I use the
Agreed. I just wanted to make this visible to you as it might be an obvious typo from the previous reverts (or a bug in the C++ code generated by |
|
@hsbadr word! Does the above stan program compile fine on your machine? If so then maybe my example above is just not capturing the issue. Also if it's possible to post the full error log from the compiler as a gist or something that would be useful |
Yes, I've successfully built your Stan code above using the Compilation ERROR, function(s)/method(s) not created!
Error in compileCode(f, code, language = language, verbose = verbose) :
instantiation of "stan::return_type_t<T_y, T_shape, T_inv_scale> stan::math::gamma_lpdf<propto,T_y,T_shape,T_inv_scale,<unnamed>>(const T_y &, const T_shape &, const T_inv_scale &) [with propto=false, T_y=std::vector<stan::math::var_value<double, void>, std::allocator<stan::math::var_value<double, void>>>, T_shape=double, T_inv_scale=double, <unnamed>=(void *)nullptr]" at line 129 of "file20fb3203c951.cpp" instantiation of "stan::scalar_type_t<VecR> model20fb746d9f75__namespace::model20fb746d9f75_::log_prob_impl<propto__,jacobian__,VecR,VecI,<unnamed>,<unnamed>>(VecR &, VecI &, std::ostream *) const [with propto__=false, jacobian__=false, VecR=Eigen::Matrix<stan::math::var, -1, 1, 0, -1, 1>, VecI=Eigen::Matrix<int, -1, 1, 0, -1, 1>, <unnamed>=(void *)nullptr, <unnamed>=(void *)nullptr]" at line 322 of "file20fb3203c951.cpp" instantiation of "T_ model20fb746d9f75__namespace::model20fb746d9f75_::log_prob<propto__,jacobian__,T_>(Eigen::Matrix<T_, |
|
@SteveBronder I think it fails in the following template: template <bool propto__, bool jacobian__, typename T_>
inline T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
std::ostream* pstream = nullptr) const {
Eigen::Matrix<int, -1, 1> params_i;
return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
}Specifically, at |
Here's the C++ code. Check lines 129 and 322. |
|
Hmm interesting. So removing the Rcpp stuff this compiles with cmdstan just fine locally. Let me try to build this using experimental rstan etc. there may be something going on there. But if that's the case then I think it's fine to merge your PR for now and I can try to investigate this more later |
Sounds good. If this PR has no side effects, it's good to go. |
This PR together with stan-dev/rstanarm#558 fixes building
rstanarmwith Stan v2.28.2.Specifically, it fixes the following error: