66#include < vector>
77
88TEST (ProbDistributionsPoissonBinomial, lpmf_length_0_length_1) {
9+ using stan::math::poisson_binomial_lpmf;
10+ using stan::math::to_array_1d;
11+ using stan::math::to_row_vector;
12+
913 Eigen::VectorXd v0 (0 );
1014 Eigen::VectorXd v1 (1 );
1115 v1 << 0.4 ;
1216
13- EXPECT_FLOAT_EQ (stan::math::poisson_binomial_lpmf (0 , v0), 0.0 );
14- EXPECT_FLOAT_EQ (stan::math::poisson_binomial_lpmf (1 , v1), std::log (0.4 ));
17+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (0 , v0), 0.0 );
18+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (0 , to_row_vector (v0)), 0.0 );
19+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (0 , to_array_1d (v0)), 0.0 );
20+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (1 , v1), std::log (0.4 ));
21+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (1 , to_row_vector (v1)), std::log (0.4 ));
22+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (1 , to_array_1d (v1)), std::log (0.4 ));
1523}
16-
1724TEST (ProbDistributionsPoissonBinomial, lpmf_length_0_length_1_vectorial_y) {
25+ using stan::math::poisson_binomial_lpmf;
26+ using stan::math::to_array_1d;
27+ using stan::math::to_row_vector;
28+
1829 Eigen::VectorXd v0 (0 );
1930 Eigen::VectorXd v1 (1 );
2031 v1 << 0.4 ;
2132
2233 std::vector<int > y0{0 , 0 };
2334 std::vector<int > y1{1 , 1 };
2435
25- EXPECT_FLOAT_EQ (stan::math::poisson_binomial_lpmf (y0, v0), 0.0 );
26- EXPECT_FLOAT_EQ (stan::math::poisson_binomial_lpmf (y1, v1), std::log (0.4 ) * 2 );
36+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y0, v0), 0.0 );
37+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y0, to_row_vector (v0)), 0.0 );
38+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y0, to_array_1d (v0)), 0.0 );
39+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y1, v1), std::log (0.4 ) * 2 );
40+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y1, to_row_vector (v1)),
41+ std::log (0.4 ) * 2 );
42+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y1, to_array_1d (v1)),
43+ std::log (0.4 ) * 2 );
2744}
2845
2946TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_scalar_arguments) {
@@ -41,25 +58,35 @@ TEST(ProbDistributionsPoissonBinomial, lpmf_works_on_scalar_arguments) {
4158
4259TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_vectorial_y) {
4360 using stan::math::poisson_binomial_lpmf;
61+ using stan::math::to_array_1d;
62+ using stan::math::to_row_vector;
4463 using vec = Eigen::Matrix<double , Eigen::Dynamic, 1 >;
4564
4665 vec p (3 , 1 );
4766 p << 0.5 , 0.2 , 0.7 ;
4867 std::vector<int > y{2 , 2 };
4968
5069 EXPECT_NEAR (-0.967584 * 2 , poisson_binomial_lpmf (y, p), 1e-6 );
70+ EXPECT_NEAR (-0.967584 * 2 , poisson_binomial_lpmf (y, to_row_vector (p)), 1e-6 );
71+ EXPECT_NEAR (-0.967584 * 2 , poisson_binomial_lpmf (y, to_array_1d (p)), 1e-6 );
5172}
5273
5374TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_vectorial_y_and_theta) {
5475 using stan::math::poisson_binomial_lpmf;
76+ using stan::math::to_array_1d;
77+ using stan::math::to_row_vector;
5578 using vec = Eigen::Matrix<double , Eigen::Dynamic, 1 >;
5679
5780 vec p (3 , 1 );
5881 p << 0.5 , 0.2 , 0.7 ;
5982 std::vector<int > y{2 , 0 };
6083 std::vector<vec> ps{p, p};
84+ std::vector<Eigen::RowVectorXd> ps_rv{to_row_vector (p), to_row_vector (p)};
85+ std::vector<std::vector<double >> ps_std{to_array_1d (p), to_array_1d (p)};
6186
6287 EXPECT_NEAR (-0.967584 - 2.12026 , poisson_binomial_lpmf (y, ps), 1e-5 );
88+ EXPECT_NEAR (-0.967584 - 2.12026 , poisson_binomial_lpmf (y, ps_rv), 1e-5 );
89+ EXPECT_NEAR (-0.967584 - 2.12026 , poisson_binomial_lpmf (y, ps_std), 1e-5 );
6390}
6491
6592TEST (ProbDistributionsPoissonBinomial,
0 commit comments