From 5cd98acf84f9fb95d1e021156fcc54a5a09f8c02 Mon Sep 17 00:00:00 2001 From: "Hamada S. Badr" Date: Wed, 22 Dec 2021 22:12:08 -0500 Subject: [PATCH 1/3] Fix no instance of overloaded function `stan::math::Holder::coeffRef` ```c++ R/library/StanHeaders/include/stan/math/prim/fun/scalar_seq_view.hpp(32): error: no instance of overloaded function "stan::math::Holder::coeffRef [with ArgType=Eigen::ArrayWrapper, 0, Eigen::Stride<0, 0>>, std::remove_reference_t>>>>, Ptrs=, 0, Eigen::Stride<0, 0>>, std::remove_reference_t>>>>>]" 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, 0, Eigen::Stride<0, 0>>, std::remove_reference_t>>>>, std::remove_reference_t, 0, Eigen::Stride<0, 0>>, std::remove_reference_t>>>>> &&> 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>::operator[](size_t={unsigned long}) const [with C=stan::ref_type_t, 0, Eigen::Stride<0, 0>>, std::remove_reference_t>>>>, std::remove_reference_t, 0, Eigen::Stride<0, 0>>, std::remove_reference_t>>>>> &&>]" at line 87 of "R/library/StanHeaders/include/stan/math/prim/prob/gamma_lpdf.hpp" instantiation of "stan::return_type_t stan::math::gamma_lpdf>(const T_y &, const T_shape &, const T_inv_scale &) [with propto=false, T_y=std::vector, std::allocator>>, T_shape=double, T_inv_scale=double, =(void *)nullptr]" at line 1547 of "stan_files/polr.hpp" instantiation of "stan::scalar_type_t model_polr_namespace::model_polr::log_prob_impl,>(VecR &, VecI &, std::ostream *) const [with propto__=false, jacobian__=false, VecR=Eigen::Matrix, VecI=Eigen::Matrix, =(void *)nullptr, =(void *)nullptr]" at line 2116 of "stan_files/polr.hpp" instantiation of "T_ model_polr_namespace::model_polr::log_prob(Eigen::Matrix &, 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::log_prob(Eigen::Matrix &, std::ostream *) const [with M=model_polr_namespace::model_polr]" ``` --- stan/math/prim/fun/scalar_seq_view.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stan/math/prim/fun/scalar_seq_view.hpp b/stan/math/prim/fun/scalar_seq_view.hpp index 59be83833f1..5e7a176b8fc 100644 --- a/stan/math/prim/fun/scalar_seq_view.hpp +++ b/stan/math/prim/fun/scalar_seq_view.hpp @@ -29,7 +29,7 @@ class scalar_seq_view> { * @param i index * @return the element at the specified position in the container */ - inline auto operator[](size_t i) const { return c_.coeffRef(i); } + inline auto operator[](size_t i) const { return c_.coeff(i); } inline auto size() const noexcept { return c_.size(); } From bf6e4fdffa194e9bf83bee3312b9ba472f100d4a Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Thu, 23 Dec 2021 15:32:34 -0500 Subject: [PATCH 2/3] make non-const operator[] method for scalar_seq_view --- stan/math/prim/fun/scalar_seq_view.hpp | 1 + stan/math/prim/prob/exp_mod_normal_lccdf.hpp | 4 ++-- stan/math/prim/prob/gamma_lpdf.hpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/stan/math/prim/fun/scalar_seq_view.hpp b/stan/math/prim/fun/scalar_seq_view.hpp index 5e7a176b8fc..b2e1b44824f 100644 --- a/stan/math/prim/fun/scalar_seq_view.hpp +++ b/stan/math/prim/fun/scalar_seq_view.hpp @@ -30,6 +30,7 @@ class scalar_seq_view> { * @return the element at the specified position in the container */ inline auto operator[](size_t i) const { return c_.coeff(i); } + inline auto& operator[](size_t i) { return c_.coeffRef(i); } inline auto size() const noexcept { return c_.size(); } diff --git a/stan/math/prim/prob/exp_mod_normal_lccdf.hpp b/stan/math/prim/prob/exp_mod_normal_lccdf.hpp index 115eb02ee81..6ec01d2f6dd 100644 --- a/stan/math/prim/prob/exp_mod_normal_lccdf.hpp +++ b/stan/math/prim/prob/exp_mod_normal_lccdf.hpp @@ -66,8 +66,8 @@ return_type_t exp_mod_normal_lccdf( scalar_seq_view y_vec(y_val); for (size_t n = 0, size_y = stan::math::size(y); n < size_y; n++) { - if (is_inf(y_vec[n])) { - return ops_partials.build(y_vec[n] > 0 ? negative_infinity() : 0); + if (is_inf(y_vec.val(n))) { + return ops_partials.build(y_vec.val(n) > 0 ? negative_infinity() : 0); } } diff --git a/stan/math/prim/prob/gamma_lpdf.hpp b/stan/math/prim/prob/gamma_lpdf.hpp index ba289902c9d..c04787422b5 100644 --- a/stan/math/prim/prob/gamma_lpdf.hpp +++ b/stan/math/prim/prob/gamma_lpdf.hpp @@ -84,7 +84,7 @@ return_type_t gamma_lpdf(const T_y& y, scalar_seq_view y_vec(y_val); for (size_t n = 0; n < stan::math::size(y); n++) { - if (y_vec[n] < 0) { + if (y_vec.val(n) < 0) { return LOG_ZERO; } } From a69f1d920e59441f62dc9ec9e611fc9844f43de9 Mon Sep 17 00:00:00 2001 From: "Hamada S. Badr" Date: Thu, 23 Dec 2021 18:43:03 -0500 Subject: [PATCH 3/3] Revert "make non-const operator[] method for scalar_seq_view" This reverts commit bf6e4fdffa194e9bf83bee3312b9ba472f100d4a. --- stan/math/prim/fun/scalar_seq_view.hpp | 1 - stan/math/prim/prob/exp_mod_normal_lccdf.hpp | 4 ++-- stan/math/prim/prob/gamma_lpdf.hpp | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/stan/math/prim/fun/scalar_seq_view.hpp b/stan/math/prim/fun/scalar_seq_view.hpp index b2e1b44824f..5e7a176b8fc 100644 --- a/stan/math/prim/fun/scalar_seq_view.hpp +++ b/stan/math/prim/fun/scalar_seq_view.hpp @@ -30,7 +30,6 @@ class scalar_seq_view> { * @return the element at the specified position in the container */ inline auto operator[](size_t i) const { return c_.coeff(i); } - inline auto& operator[](size_t i) { return c_.coeffRef(i); } inline auto size() const noexcept { return c_.size(); } diff --git a/stan/math/prim/prob/exp_mod_normal_lccdf.hpp b/stan/math/prim/prob/exp_mod_normal_lccdf.hpp index 6ec01d2f6dd..115eb02ee81 100644 --- a/stan/math/prim/prob/exp_mod_normal_lccdf.hpp +++ b/stan/math/prim/prob/exp_mod_normal_lccdf.hpp @@ -66,8 +66,8 @@ return_type_t exp_mod_normal_lccdf( scalar_seq_view y_vec(y_val); for (size_t n = 0, size_y = stan::math::size(y); n < size_y; n++) { - if (is_inf(y_vec.val(n))) { - return ops_partials.build(y_vec.val(n) > 0 ? negative_infinity() : 0); + if (is_inf(y_vec[n])) { + return ops_partials.build(y_vec[n] > 0 ? negative_infinity() : 0); } } diff --git a/stan/math/prim/prob/gamma_lpdf.hpp b/stan/math/prim/prob/gamma_lpdf.hpp index c04787422b5..ba289902c9d 100644 --- a/stan/math/prim/prob/gamma_lpdf.hpp +++ b/stan/math/prim/prob/gamma_lpdf.hpp @@ -84,7 +84,7 @@ return_type_t gamma_lpdf(const T_y& y, scalar_seq_view y_vec(y_val); for (size_t n = 0; n < stan::math::size(y); n++) { - if (y_vec.val(n) < 0) { + if (y_vec[n] < 0) { return LOG_ZERO; } }