6
6
#include < vector>
7
7
8
8
TEST (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
+
9
13
Eigen::VectorXd v0 (0 );
10
14
Eigen::VectorXd v1 (1 );
11
15
v1 << 0.4 ;
12
16
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 ));
15
23
}
16
-
17
24
TEST (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
+
18
29
Eigen::VectorXd v0 (0 );
19
30
Eigen::VectorXd v1 (1 );
20
31
v1 << 0.4 ;
21
32
22
33
std::vector<int > y0 {0 , 0 };
23
34
std::vector<int > y1 {1 , 1 };
24
35
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 );
27
44
}
28
45
29
46
TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_scalar_arguments) {
@@ -41,25 +58,35 @@ TEST(ProbDistributionsPoissonBinomial, lpmf_works_on_scalar_arguments) {
41
58
42
59
TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_vectorial_y) {
43
60
using stan::math::poisson_binomial_lpmf;
61
+ using stan::math::to_array_1d;
62
+ using stan::math::to_row_vector;
44
63
using vec = Eigen::Matrix<double , Eigen::Dynamic, 1 >;
45
64
46
65
vec p (3 , 1 );
47
66
p << 0.5 , 0.2 , 0.7 ;
48
67
std::vector<int > y{2 , 2 };
49
68
50
69
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 );
51
72
}
52
73
53
74
TEST (ProbDistributionsPoissonBinomial, lpmf_works_on_vectorial_y_and_theta) {
54
75
using stan::math::poisson_binomial_lpmf;
76
+ using stan::math::to_array_1d;
77
+ using stan::math::to_row_vector;
55
78
using vec = Eigen::Matrix<double , Eigen::Dynamic, 1 >;
56
79
57
80
vec p (3 , 1 );
58
81
p << 0.5 , 0.2 , 0.7 ;
59
82
std::vector<int > y{2 , 0 };
60
83
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)};
61
86
62
87
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 );
63
90
}
64
91
65
92
TEST (ProbDistributionsPoissonBinomial,
0 commit comments