Skip to content

Commit 6dfa2ed

Browse files
committed
student_t_qf only returns column eigen vectors now
1 parent 726f991 commit 6dfa2ed

6 files changed

Lines changed: 22 additions & 102 deletions

File tree

stan/math/prim/meta.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
#include <stan/math/prim/meta/ad_promotable.hpp>
7272
#include <stan/math/prim/meta/append_return_type.hpp>
7373
#include <stan/math/prim/meta/base_type.hpp>
74-
#include <stan/math/prim/meta/common_container_type.hpp>
7574
#include <stan/math/prim/meta/contains_std_vector.hpp>
7675
#include <stan/math/prim/meta/contains_tuple.hpp>
7776
#include <stan/math/prim/meta/error_index.hpp>

stan/math/prim/meta/common_container_type.hpp

Lines changed: 0 additions & 77 deletions
This file was deleted.

stan/math/prim/meta/is_vector.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ using require_eigen_row_vector_t
184184
* member with a value of false.
185185
*/
186186
template <typename T>
187-
struct is_row_vector : internal::is_row_vector_impl<T> {};
187+
struct is_row_vector : internal::is_row_vector_impl<std::decay_t<T>> {};
188+
189+
template <typename T>
190+
inline constexpr bool is_row_vector_v = is_row_vector<T>::value;
188191

189192
/*! \ingroup require_eigens_types */
190193
/*! \defgroup row_vector_types row_vector */

stan/math/prim/prob/student_t_qf.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stan/math/prim/fun/sqrt.hpp>
77
#include <stan/math/prim/fun/inv_inc_beta.hpp>
88
#include <stan/math/prim/fun/max_size.hpp>
9+
#include <stan/math/prim/fun/to_ref.hpp>
910

1011
namespace stan {
1112
namespace math {
@@ -70,20 +71,20 @@ template <typename T_p, typename T_nu, typename T_mu, typename T_sigma,
7071
require_any_vector_t<T_p, T_nu, T_mu, T_sigma>* = nullptr>
7172
inline auto student_t_qf(const T_p& p, const T_nu& nu, const T_mu& mu,
7273
const T_sigma& sigma) {
73-
using T_container = common_container_t<T_p, T_nu, T_mu, T_sigma>;
74+
using ret_scalar = return_type_t<T_p, T_nu, T_mu, T_sigma>;
7475
static constexpr const char* function = "student_t_qf";
7576
const size_t max_size_all = max_size(p, nu, mu, sigma);
76-
T_container result(max_size_all);
77+
Eigen::Matrix<ret_scalar, -1, 1> result(max_size_all);
7778

78-
ref_type_t<T_p> p_ref = p;
79-
ref_type_t<T_nu> nu_ref = nu;
80-
ref_type_t<T_mu> mu_ref = mu;
81-
ref_type_t<T_sigma> sigma_ref = sigma;
79+
decltype(auto) p_ref = to_ref(p);
80+
decltype(auto) nu_ref = to_ref(nu);
81+
decltype(auto) mu_ref = to_ref(mu);
82+
decltype(auto) sigma_ref = to_ref(sigma);
8283

83-
scalar_seq_view<ref_type_t<T_p>> p_vec(p_ref);
84-
scalar_seq_view<ref_type_t<T_nu>> nu_vec(nu_ref);
85-
scalar_seq_view<ref_type_t<T_mu>> mu_vec(mu_ref);
86-
scalar_seq_view<ref_type_t<T_sigma>> sigma_vec(sigma_ref);
84+
scalar_seq_view<decltype(p_ref)> p_vec(p_ref);
85+
scalar_seq_view<decltype(nu_ref)> nu_vec(nu_ref);
86+
scalar_seq_view<decltype(mu_ref)> mu_vec(mu_ref);
87+
scalar_seq_view<decltype(sigma_ref)> sigma_vec(sigma_ref);
8788

8889
for (size_t i = 0; i < max_size_all; ++i) {
8990
result[i] = student_t_qf(p_vec[i], nu_vec[i], mu_vec[i], sigma_vec[i]);

test/unit/math/mix/prob/student_t_qf_test.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ TEST_F(AgradRev, mathMixProb_student_t_qf) {
1616
stan::test::expect_ad(f, 0.8, 0.5, 0.1);
1717
stan::test::expect_ad(f, 0.1, 3, 3);
1818

19-
Eigen::VectorXd p(3);
20-
p << 0.3, 0.8, 0.1;
19+
Eigen::VectorXd p{{0.3, 0.8, 0.1}};
2120

22-
Eigen::VectorXd nu(3);
23-
nu << 0.5, 0.5, 3;
21+
Eigen::VectorXd nu{{0.5, 0.5, 3}};
2422

25-
Eigen::VectorXd sigma(3);
26-
sigma << 3, 0.1, 3;
23+
Eigen::VectorXd sigma{{3, 0.1, 3}};
2724

2825
stan::test::expect_ad(f, p, nu, sigma);
2926
}

test/unit/math/prim/prob/student_t_qf_test.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
TEST(MathFunctions, student_t_qf_vals) {
77
using stan::math::student_t_qf;
88

9-
Eigen::VectorXd p(5);
10-
p << 0.1, 0.2, 0.5, 0.8, 0.9;
9+
Eigen::VectorXd p{{0.1, 0.2, 0.5, 0.8, 0.9}};
1110

1211
Eigen::VectorXd res = student_t_qf(p, 4, 2, 3);
1312

@@ -21,11 +20,9 @@ TEST(MathFunctions, student_t_qf_vals) {
2120
TEST(MathFunctions, student_t_qf_vec) {
2221
using stan::math::student_t_qf;
2322

24-
Eigen::VectorXd p(5);
25-
p << 0.1, 0.2, 0.5, 0.8, 0.9;
23+
Eigen::VectorXd p{{0.1, 0.2, 0.5, 0.8, 0.9}};
2624

27-
Eigen::VectorXd nu(5);
28-
nu << 4, 4, 3, 3, 3;
25+
Eigen::VectorXd nu{{4, 4, 3, 3, 3}};
2926

3027
Eigen::VectorXd res(5);
3128
for (int i = 0; i < 5; ++i) {
@@ -37,7 +34,7 @@ TEST(MathFunctions, student_t_qf_vec) {
3734
Eigen::RowVectorXd nu_rowvec = nu.transpose();
3835
Eigen::RowVectorXd res_rowvec = res.transpose();
3936

40-
EXPECT_MATRIX_FLOAT_EQ(res_rowvec, student_t_qf(p_rowvec, nu_rowvec, 2, 3));
37+
EXPECT_MATRIX_FLOAT_EQ(res, student_t_qf(p_rowvec, nu_rowvec, 2, 3));
4138
}
4239

4340
TEST(MathFunctions, student_t_qf_inf) {

0 commit comments

Comments
 (0)