From 6dfa2edba1a07d31f12ba0f2ca30e3052e7c8cb7 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Thu, 7 May 2026 13:16:22 -0400 Subject: [PATCH] student_t_qf only returns column eigen vectors now --- stan/math/prim/meta.hpp | 1 - stan/math/prim/meta/common_container_type.hpp | 77 ------------------- stan/math/prim/meta/is_vector.hpp | 5 +- stan/math/prim/prob/student_t_qf.hpp | 21 ++--- test/unit/math/mix/prob/student_t_qf_test.cpp | 9 +-- .../unit/math/prim/prob/student_t_qf_test.cpp | 11 +-- 6 files changed, 22 insertions(+), 102 deletions(-) delete mode 100644 stan/math/prim/meta/common_container_type.hpp diff --git a/stan/math/prim/meta.hpp b/stan/math/prim/meta.hpp index 4c100329250..5407f128133 100644 --- a/stan/math/prim/meta.hpp +++ b/stan/math/prim/meta.hpp @@ -71,7 +71,6 @@ #include #include #include -#include #include #include #include diff --git a/stan/math/prim/meta/common_container_type.hpp b/stan/math/prim/meta/common_container_type.hpp deleted file mode 100644 index df74fddff5a..00000000000 --- a/stan/math/prim/meta/common_container_type.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef STAN_MATH_PRIM_META_COMMON_CONTAINER_TYPE_HPP -#define STAN_MATH_PRIM_META_COMMON_CONTAINER_TYPE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace stan { -namespace internal { -template -struct common_container_type_impl; - -template -struct common_container_type_impl, - require_stan_scalar_t> { - using type = return_type_t; -}; - -template -struct common_container_type_impl, - require_container_t> { - using return_t = return_type_t; - using container_type_1 = math::promote_scalar_t>; - using container_type_2 = math::promote_scalar_t>; - using type = std::conditional_t< - std::is_same::value, container_type_1, - void>; -}; - -template -struct common_container_type_impl, - require_container_t> { - using type = math::promote_scalar_t, plain_type_t>; -}; - -template -struct common_container_type_impl, - require_stan_scalar_t> { - using type = math::promote_scalar_t, plain_type_t>; -}; -} // namespace internal - -template -struct common_container_type; - -template -struct common_container_type { - using type = typename internal::common_container_type_impl< - T, double>::type; // Use double for base case -}; - -/** - * Determine the common container type for a variadic list of types. - * If all types are scalars, then the common scalar type is returned. - * If all container types the same, but not necessarily the same scalar type, - * the common container type with the common scalar type is returned. - * - * If different container types are present, the result is `void`. - */ -template -struct common_container_type { - using type = typename internal::common_container_type_impl< - T1, typename common_container_type::type>::type; -}; - -template -using common_container_t = typename common_container_type::type; - -} // namespace stan - -#endif // STAN_MATH_PRIM_META_PLAIN_TYPE_HPP diff --git a/stan/math/prim/meta/is_vector.hpp b/stan/math/prim/meta/is_vector.hpp index 697454c29fa..9b7aa67daf0 100644 --- a/stan/math/prim/meta/is_vector.hpp +++ b/stan/math/prim/meta/is_vector.hpp @@ -184,7 +184,10 @@ using require_eigen_row_vector_t * member with a value of false. */ template -struct is_row_vector : internal::is_row_vector_impl {}; +struct is_row_vector : internal::is_row_vector_impl> {}; + +template +inline constexpr bool is_row_vector_v = is_row_vector::value; /*! \ingroup require_eigens_types */ /*! \defgroup row_vector_types row_vector */ diff --git a/stan/math/prim/prob/student_t_qf.hpp b/stan/math/prim/prob/student_t_qf.hpp index 25f74cc6e5b..5a4b9dbf920 100644 --- a/stan/math/prim/prob/student_t_qf.hpp +++ b/stan/math/prim/prob/student_t_qf.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace stan { namespace math { @@ -70,20 +71,20 @@ template * = nullptr> inline auto student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu, const T_sigma& sigma) { - using T_container = common_container_t; + using ret_scalar = return_type_t; static constexpr const char* function = "student_t_qf"; const size_t max_size_all = max_size(p, nu, mu, sigma); - T_container result(max_size_all); + Eigen::Matrix result(max_size_all); - ref_type_t p_ref = p; - ref_type_t nu_ref = nu; - ref_type_t mu_ref = mu; - ref_type_t sigma_ref = sigma; + decltype(auto) p_ref = to_ref(p); + decltype(auto) nu_ref = to_ref(nu); + decltype(auto) mu_ref = to_ref(mu); + decltype(auto) sigma_ref = to_ref(sigma); - scalar_seq_view> p_vec(p_ref); - scalar_seq_view> nu_vec(nu_ref); - scalar_seq_view> mu_vec(mu_ref); - scalar_seq_view> sigma_vec(sigma_ref); + scalar_seq_view p_vec(p_ref); + scalar_seq_view nu_vec(nu_ref); + scalar_seq_view mu_vec(mu_ref); + scalar_seq_view sigma_vec(sigma_ref); for (size_t i = 0; i < max_size_all; ++i) { result[i] = student_t_qf(p_vec[i], nu_vec[i], mu_vec[i], sigma_vec[i]); diff --git a/test/unit/math/mix/prob/student_t_qf_test.cpp b/test/unit/math/mix/prob/student_t_qf_test.cpp index 1e5dc213b3c..9b9cb37c9a8 100644 --- a/test/unit/math/mix/prob/student_t_qf_test.cpp +++ b/test/unit/math/mix/prob/student_t_qf_test.cpp @@ -16,14 +16,11 @@ TEST_F(AgradRev, mathMixProb_student_t_qf) { stan::test::expect_ad(f, 0.8, 0.5, 0.1); stan::test::expect_ad(f, 0.1, 3, 3); - Eigen::VectorXd p(3); - p << 0.3, 0.8, 0.1; + Eigen::VectorXd p{{0.3, 0.8, 0.1}}; - Eigen::VectorXd nu(3); - nu << 0.5, 0.5, 3; + Eigen::VectorXd nu{{0.5, 0.5, 3}}; - Eigen::VectorXd sigma(3); - sigma << 3, 0.1, 3; + Eigen::VectorXd sigma{{3, 0.1, 3}}; stan::test::expect_ad(f, p, nu, sigma); } diff --git a/test/unit/math/prim/prob/student_t_qf_test.cpp b/test/unit/math/prim/prob/student_t_qf_test.cpp index 67009d0c771..4694264870d 100644 --- a/test/unit/math/prim/prob/student_t_qf_test.cpp +++ b/test/unit/math/prim/prob/student_t_qf_test.cpp @@ -6,8 +6,7 @@ TEST(MathFunctions, student_t_qf_vals) { using stan::math::student_t_qf; - Eigen::VectorXd p(5); - p << 0.1, 0.2, 0.5, 0.8, 0.9; + Eigen::VectorXd p{{0.1, 0.2, 0.5, 0.8, 0.9}}; Eigen::VectorXd res = student_t_qf(p, 4, 2, 3); @@ -21,11 +20,9 @@ TEST(MathFunctions, student_t_qf_vals) { TEST(MathFunctions, student_t_qf_vec) { using stan::math::student_t_qf; - Eigen::VectorXd p(5); - p << 0.1, 0.2, 0.5, 0.8, 0.9; + Eigen::VectorXd p{{0.1, 0.2, 0.5, 0.8, 0.9}}; - Eigen::VectorXd nu(5); - nu << 4, 4, 3, 3, 3; + Eigen::VectorXd nu{{4, 4, 3, 3, 3}}; Eigen::VectorXd res(5); for (int i = 0; i < 5; ++i) { @@ -37,7 +34,7 @@ TEST(MathFunctions, student_t_qf_vec) { Eigen::RowVectorXd nu_rowvec = nu.transpose(); Eigen::RowVectorXd res_rowvec = res.transpose(); - EXPECT_MATRIX_FLOAT_EQ(res_rowvec, student_t_qf(p_rowvec, nu_rowvec, 2, 3)); + EXPECT_MATRIX_FLOAT_EQ(res, student_t_qf(p_rowvec, nu_rowvec, 2, 3)); } TEST(MathFunctions, student_t_qf_inf) {