|
1 | | -// #include <test/unit/math/test_ad.hpp> |
| 1 | +#include <test/unit/math/test_ad.hpp> |
2 | 2 |
|
3 | | -// namespace stochastic_row_constrain_test { |
4 | | -// template <typename T> |
5 | | -// T g1(const T& x) { |
6 | | -// stan::scalar_type_t<T> lp = 0; |
7 | | -// return stan::math::stochastic_row_constrain<false>(x, lp); |
8 | | -// } |
9 | | -// template <typename T> |
10 | | -// T g2(const T& x) { |
11 | | -// stan::scalar_type_t<T> lp = 0; |
12 | | -// return stan::math::stochastic_row_constrain<true>(x, lp); |
13 | | -// } |
14 | | -// template <typename T> |
15 | | -// typename stan::scalar_type<T>::type g3(const T& x) { |
16 | | -// stan::scalar_type_t<T> lp = 0; |
17 | | -// stan::math::stochastic_row_constrain<true>(x, lp); |
18 | | -// return lp; |
19 | | -// } |
| 3 | +namespace stochastic_row_constrain_test { |
| 4 | +template <typename T> |
| 5 | +T g1(const T& x) { |
| 6 | + stan::scalar_type_t<T> lp = 0; |
| 7 | + return stan::math::stochastic_row_constrain<false>(x, lp); |
| 8 | +} |
| 9 | +template <typename T> |
| 10 | +T g2(const T& x) { |
| 11 | + stan::scalar_type_t<T> lp = 0; |
| 12 | + return stan::math::stochastic_row_constrain<true>(x, lp); |
| 13 | +} |
| 14 | +template <typename T> |
| 15 | +typename stan::scalar_type<T>::type g3(const T& x) { |
| 16 | + stan::scalar_type_t<T> lp = 0; |
| 17 | + stan::math::stochastic_row_constrain<true>(x, lp); |
| 18 | + return lp; |
| 19 | +} |
20 | 20 |
|
21 | | -// template <typename T> |
22 | | -// void expect_simplex_transform(const T& x) { |
23 | | -// auto f1 = [](const auto& x) { return g1(x); }; |
24 | | -// auto f2 = [](const auto& x) { return g2(x); }; |
25 | | -// auto f3 = [](const auto& x) { return g3(x); }; |
26 | | -// stan::test::expect_ad(f1, x); |
27 | | -// stan::test::expect_ad_matvar(f1, x); |
28 | | -// stan::test::expect_ad(f2, x); |
29 | | -// stan::test::expect_ad_matvar(f2, x); |
30 | | -// stan::test::expect_ad(f3, x); |
31 | | -// stan::test::expect_ad_matvar(f3, x); |
32 | | -// } |
33 | | -// } // namespace stochastic_row_constrain_test |
| 21 | +template <typename T> |
| 22 | +void expect_simplex_transform(const T& x) { |
| 23 | + auto f1 = [](const auto& x) { return g1(x); }; |
| 24 | + auto f2 = [](const auto& x) { return g2(x); }; |
| 25 | + auto f3 = [](const auto& x) { return g3(x); }; |
| 26 | + stan::test::expect_ad(f1, x); |
| 27 | + stan::test::expect_ad_matvar(f1, x); |
| 28 | + stan::test::expect_ad(f2, x); |
| 29 | + stan::test::expect_ad_matvar(f2, x); |
| 30 | + stan::test::expect_ad(f3, x); |
| 31 | + stan::test::expect_ad_matvar(f3, x); |
| 32 | +} |
| 33 | +} // namespace stochastic_row_constrain_test |
34 | 34 |
|
35 | | -// TEST(MathMixMatFun, simplexRowTransform0) { |
36 | | -// Eigen::MatrixXd v0(0, 0); |
37 | | -// stochastic_row_constrain_test::expect_simplex_transform(v0); |
38 | | -// } |
39 | | -// TEST(MathMixMatFun, simplexRowTransform1) { |
40 | | -// Eigen::MatrixXd v1(1, 3); |
41 | | -// v1 << .01, .1, 1; |
42 | | -// stochastic_row_constrain_test::expect_simplex_transform(v1); |
43 | | -// } |
| 35 | +TEST(MathMixMatFun, simplexRowTransform0) { |
| 36 | + Eigen::MatrixXd v0(0, 0); |
| 37 | + stochastic_row_constrain_test::expect_simplex_transform(v0); |
| 38 | +} |
| 39 | +TEST(MathMixMatFun, simplexRowTransform1) { |
| 40 | + Eigen::MatrixXd v1(1, 3); |
| 41 | + v1 << .01, .1, 1; |
| 42 | + stochastic_row_constrain_test::expect_simplex_transform(v1); |
| 43 | +} |
44 | 44 |
|
45 | | -// TEST(MathMixMatFun, simplexRowTransform2) { |
46 | | -// Eigen::MatrixXd v2(2, 3); |
47 | | -// v2 << 3, -1, 3, -1, 3, -1; |
48 | | -// stochastic_row_constrain_test::expect_simplex_transform(v2); |
49 | | -// } |
| 45 | +TEST(MathMixMatFun, simplexRowTransform2) { |
| 46 | + Eigen::MatrixXd v2(2, 3); |
| 47 | + v2 << 3, -1, 3, -1, 3, -1; |
| 48 | + stochastic_row_constrain_test::expect_simplex_transform(v2); |
| 49 | +} |
50 | 50 |
|
51 | | -// TEST(MathMixMatFun, simplexRowTransform3) { |
52 | | -// Eigen::MatrixXd v3(3, 3); |
53 | | -// v3 << 2, 3, -1, 2, 3, -1, 2, 3, -1; |
54 | | -// stochastic_row_constrain_test::expect_simplex_transform(v3); |
55 | | -// } |
56 | | -// TEST(MathMixMatFun, simplexRowTransform4) { |
57 | | -// Eigen::MatrixXd v4(4, 3); |
58 | | -// v4 << 2, -1, 0, -1.1, 2, -1, 0, -1.1, 2, -1, 0, -1.1; |
59 | | -// stochastic_row_constrain_test::expect_simplex_transform(v4); |
60 | | -// } |
61 | | -// TEST(MathMixMatFun, simplexRowTransform5) { |
62 | | -// Eigen::MatrixXd v5(5, 3); |
63 | | -// v5 << 1, -3, 2, 0, -1, 1, -3, 2, 0, -1, 1, -3, 2, 0, -1; |
64 | | -// stochastic_row_constrain_test::expect_simplex_transform(v5); |
65 | | -// } |
| 51 | +TEST(MathMixMatFun, simplexRowTransform3) { |
| 52 | + Eigen::MatrixXd v3(3, 3); |
| 53 | + v3 << 2, 3, -1, 2, 3, -1, 2, 3, -1; |
| 54 | + stochastic_row_constrain_test::expect_simplex_transform(v3); |
| 55 | +} |
| 56 | +TEST(MathMixMatFun, simplexRowTransform4) { |
| 57 | + Eigen::MatrixXd v4(4, 3); |
| 58 | + v4 << 2, -1, 0, -1.1, 2, -1, 0, -1.1, 2, -1, 0, -1.1; |
| 59 | + stochastic_row_constrain_test::expect_simplex_transform(v4); |
| 60 | +} |
| 61 | +TEST(MathMixMatFun, simplexRowTransform5) { |
| 62 | + Eigen::MatrixXd v5(5, 3); |
| 63 | + v5 << 1, -3, 2, 0, -1, 1, -3, 2, 0, -1, 1, -3, 2, 0, -1; |
| 64 | + stochastic_row_constrain_test::expect_simplex_transform(v5); |
| 65 | +} |
0 commit comments