66#include < vector>
77
88TEST (ProbDistributionsPoissonBinomial, lpmf_length_0_length_1) {
9+ using stan::math::poisson_binomial_lpmf;
10+ using stan::math::to_row_vector;
11+ using stan::math::to_array_1d;
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_row_vector;
27+ using stan::math::to_array_1d;
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)), std::log (0.4 ) * 2 );
41+ EXPECT_FLOAT_EQ (poisson_binomial_lpmf (y1, to_array_1d (v1)), std::log (0.4 ) * 2 );
2742}
2843
2944TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_scalar_arguments) {
@@ -41,25 +56,35 @@ TEST(ProbDistributionsPoissonBinomial, lpmf_works_on_scalar_arguments) {
4156
4257TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_vectorial_y) {
4358 using stan::math::poisson_binomial_lpmf;
59+ using stan::math::to_row_vector;
60+ using stan::math::to_array_1d;
4461 using vec = Eigen::Matrix<double , Eigen::Dynamic, 1 >;
4562
4663 vec p (3 , 1 );
4764 p << 0.5 , 0.2 , 0.7 ;
4865 std::vector<int > y{2 , 2 };
4966
5067 EXPECT_NEAR (-0.967584 * 2 , poisson_binomial_lpmf (y, p), 1e-6 );
68+ EXPECT_NEAR (-0.967584 * 2 , poisson_binomial_lpmf (y, to_row_vector (p)), 1e-6 );
69+ EXPECT_NEAR (-0.967584 * 2 , poisson_binomial_lpmf (y, to_array_1d (p)), 1e-6 );
5170}
5271
5372TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_vectorial_y_and_theta) {
5473 using stan::math::poisson_binomial_lpmf;
74+ using stan::math::to_row_vector;
75+ using stan::math::to_array_1d;
5576 using vec = Eigen::Matrix<double , Eigen::Dynamic, 1 >;
5677
5778 vec p (3 , 1 );
5879 p << 0.5 , 0.2 , 0.7 ;
5980 std::vector<int > y{2 , 0 };
6081 std::vector<vec> ps{p, p};
82+ std::vector<Eigen::RowVectorXd> ps_rv{to_row_vector (p), to_row_vector (p)};
83+ std::vector<std::vector<double >> ps_std{to_array_1d (p), to_array_1d (p)};
6184
6285 EXPECT_NEAR (-0.967584 - 2.12026 , poisson_binomial_lpmf (y, ps), 1e-5 );
86+ EXPECT_NEAR (-0.967584 - 2.12026 , poisson_binomial_lpmf (y, ps_rv), 1e-5 );
87+ EXPECT_NEAR (-0.967584 - 2.12026 , poisson_binomial_lpmf (y, ps_std), 1e-5 );
6388}
6489
6590TEST (ProbDistributionsPoissonBinomial,
0 commit comments