Skip to content

Commit e8f3058

Browse files
committed
Revert "Comment out stochastic matrix tests for now"
This reverts commit 3e0ce29.
1 parent dde6950 commit e8f3058

4 files changed

Lines changed: 205 additions & 207 deletions

File tree

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
1-
// #include <test/unit/math/test_ad.hpp>
2-
3-
// namespace stochastic_column_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_column_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_column_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_column_constrain<true>(x, lp);
18-
// return lp;
19-
// }
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_column_constrain_test
34-
35-
// TEST(MathMixMatFun, simplexColumnTransform) {
36-
// Eigen::MatrixXd v0(0, 0);
37-
// stochastic_column_constrain_test::expect_simplex_transform(v0);
38-
39-
// Eigen::MatrixXd v1(1, 3);
40-
// v1 << 1, 2, 3;
41-
// stochastic_column_constrain_test::expect_simplex_transform(v1);
42-
43-
// Eigen::MatrixXd v2(2, 3);
44-
// v2 << 3, -1, 3, -1, 3, -1;
45-
// stochastic_column_constrain_test::expect_simplex_transform(v2);
46-
47-
// Eigen::MatrixXd v3(3, 3);
48-
// v3 << 2, 3, -1, 2, 3, -1, 2, 3, -1;
49-
// stochastic_column_constrain_test::expect_simplex_transform(v3);
50-
51-
// Eigen::MatrixXd v4(4, 3);
52-
// v4 << 2, -1, 0, -1.1, 2, -1, 0, -1.1, 2, -1, 0, -1.1;
53-
// stochastic_column_constrain_test::expect_simplex_transform(v4);
54-
55-
// Eigen::MatrixXd v5(5, 3);
56-
// v5 << 1, -3, 2, 0, -1, 1, -3, 2, 0, -1, 1, -3, 2, 0, -1;
57-
// stochastic_column_constrain_test::expect_simplex_transform(v5);
58-
// }
1+
#include <test/unit/math/test_ad.hpp>
2+
3+
namespace stochastic_column_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_column_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_column_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_column_constrain<true>(x, lp);
18+
return lp;
19+
}
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_column_constrain_test
34+
35+
TEST(MathMixMatFun, simplexColumnTransform) {
36+
Eigen::MatrixXd v0(0, 0);
37+
stochastic_column_constrain_test::expect_simplex_transform(v0);
38+
39+
Eigen::MatrixXd v1(1, 3);
40+
v1 << 1, 2, 3;
41+
stochastic_column_constrain_test::expect_simplex_transform(v1);
42+
43+
Eigen::MatrixXd v2(2, 3);
44+
v2 << 3, -1, 3, -1, 3, -1;
45+
stochastic_column_constrain_test::expect_simplex_transform(v2);
46+
47+
Eigen::MatrixXd v3(3, 3);
48+
v3 << 2, 3, -1, 2, 3, -1, 2, 3, -1;
49+
stochastic_column_constrain_test::expect_simplex_transform(v3);
50+
51+
Eigen::MatrixXd v4(4, 3);
52+
v4 << 2, -1, 0, -1.1, 2, -1, 0, -1.1, 2, -1, 0, -1.1;
53+
stochastic_column_constrain_test::expect_simplex_transform(v4);
54+
55+
Eigen::MatrixXd v5(5, 3);
56+
v5 << 1, -3, 2, 0, -1, 1, -3, 2, 0, -1, 1, -3, 2, 0, -1;
57+
stochastic_column_constrain_test::expect_simplex_transform(v5);
58+
}
Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
// #include <test/unit/math/test_ad.hpp>
1+
#include <test/unit/math/test_ad.hpp>
22

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+
}
2020

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
3434

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+
}
4444

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+
}
5050

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+
}
Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
1-
// #include <stan/math/prim.hpp>
2-
// #include <test/unit/util.hpp>
3-
// #include <gtest/gtest.h>
1+
#include <stan/math/prim.hpp>
2+
#include <test/unit/util.hpp>
3+
#include <gtest/gtest.h>
44

5-
// TEST(prob_transform, stochastic_column_rt0) {
6-
// using Eigen::Dynamic;
7-
// using Eigen::Matrix;
8-
// Matrix<double, Dynamic, Dynamic> x(4, 4);
9-
// for (Eigen::Index i = 0; i < x.size(); ++i) {
10-
// x(i) = static_cast<double>(i);
11-
// }
12-
// double lp = 0;
13-
// Matrix<double, Dynamic, Dynamic> x_test
14-
// = stan::math::stochastic_column_constrain<false>(x, lp);
15-
// EXPECT_EQ(lp, 0.0);
16-
// Matrix<double, Dynamic, Dynamic> x_res(5, 4);
17-
// double lp_orig = 0.0;
18-
// for (Eigen::Index i = 0; i < x.cols(); ++i) {
19-
// x_res.col(i) = stan::math::simplex_constrain<false>(x.col(i), lp_orig);
20-
// }
21-
// EXPECT_EQ(lp_orig, 0.0);
22-
// EXPECT_MATRIX_EQ(x_test, x_res);
23-
// Matrix<double, Dynamic, Dynamic> x_lp_test
24-
// = stan::math::stochastic_column_constrain<true>(x, lp);
25-
// for (Eigen::Index i = 0; i < x.cols(); ++i) {
26-
// x_res.col(i) = stan::math::simplex_constrain<true>(x.col(i), lp_orig);
27-
// }
28-
// EXPECT_MATRIX_EQ(x_lp_test, x_res);
29-
// }
5+
TEST(prob_transform, stochastic_column_rt0) {
6+
using Eigen::Dynamic;
7+
using Eigen::Matrix;
8+
Matrix<double, Dynamic, Dynamic> x(4, 4);
9+
for (Eigen::Index i = 0; i < x.size(); ++i) {
10+
x(i) = static_cast<double>(i);
11+
}
12+
double lp = 0;
13+
Matrix<double, Dynamic, Dynamic> x_test
14+
= stan::math::stochastic_column_constrain<false>(x, lp);
15+
EXPECT_EQ(lp, 0.0);
16+
Matrix<double, Dynamic, Dynamic> x_res(5, 4);
17+
double lp_orig = 0.0;
18+
for (Eigen::Index i = 0; i < x.cols(); ++i) {
19+
x_res.col(i) = stan::math::simplex_constrain<false>(x.col(i), lp_orig);
20+
}
21+
EXPECT_EQ(lp_orig, 0.0);
22+
EXPECT_MATRIX_EQ(x_test, x_res);
23+
Matrix<double, Dynamic, Dynamic> x_lp_test
24+
= stan::math::stochastic_column_constrain<true>(x, lp);
25+
for (Eigen::Index i = 0; i < x.cols(); ++i) {
26+
x_res.col(i) = stan::math::simplex_constrain<true>(x.col(i), lp_orig);
27+
}
28+
EXPECT_MATRIX_EQ(x_lp_test, x_res);
29+
}
3030

31-
// TEST(prob_transform, stochastic_column_constrain_and_free) {
32-
// using Eigen::Dynamic;
33-
// using Eigen::Matrix;
34-
// Matrix<double, Dynamic, Dynamic> x(4, 4);
35-
// for (Eigen::Index i = 0; i < x.size(); ++i) {
36-
// x(i) = static_cast<double>(i);
37-
// }
38-
// double lp = 0;
39-
// Matrix<double, Dynamic, Dynamic> x_test =
40-
// stan::math::stochastic_column_free(
41-
// stan::math::stochastic_column_constrain<false>(x, lp));
42-
// EXPECT_MATRIX_NEAR(x, x_test, 1e-9);
31+
TEST(prob_transform, stochastic_column_constrain_and_free) {
32+
using Eigen::Dynamic;
33+
using Eigen::Matrix;
34+
Matrix<double, Dynamic, Dynamic> x(4, 4);
35+
for (Eigen::Index i = 0; i < x.size(); ++i) {
36+
x(i) = static_cast<double>(i);
37+
}
38+
double lp = 0;
39+
Matrix<double, Dynamic, Dynamic> x_test = stan::math::stochastic_column_free(
40+
stan::math::stochastic_column_constrain<false>(x, lp));
41+
EXPECT_MATRIX_NEAR(x, x_test, 1e-9);
4342

44-
// Matrix<double, Dynamic, Dynamic> x_lp_test
45-
// = stan::math::stochastic_column_free(
46-
// stan::math::stochastic_column_constrain<true>(x, lp));
47-
// EXPECT_MATRIX_NEAR(x, x_lp_test, 1e-9);
48-
// }
43+
Matrix<double, Dynamic, Dynamic> x_lp_test
44+
= stan::math::stochastic_column_free(
45+
stan::math::stochastic_column_constrain<true>(x, lp));
46+
EXPECT_MATRIX_NEAR(x, x_lp_test, 1e-9);
47+
}

0 commit comments

Comments
 (0)