2
2
#include < vector>
3
3
#include < gtest/gtest.h>
4
4
5
- TEST (mathMixMatFun, ad_tests ) {
5
+ TEST (mathMixMatFun, gen_inv_test_1 ) {
6
6
using stan::test::expect_ad;
7
7
using stan::test::expect_ad_matvar;
8
8
@@ -11,25 +11,61 @@ TEST(mathMixMatFun, ad_tests) {
11
11
Eigen::MatrixXd t (0 , 0 );
12
12
expect_ad (f, t);
13
13
expect_ad_matvar (f, t);
14
+ }
15
+
16
+ TEST (mathMixMatFun, gen_inv_test_2) {
17
+ using stan::test::expect_ad;
18
+ using stan::test::expect_ad_matvar;
19
+
20
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
14
21
15
22
Eigen::MatrixXd u (1 , 1 );
16
23
u << 2 ;
17
24
expect_ad (f, u);
18
25
expect_ad_matvar (f, u);
26
+ }
27
+
28
+ TEST (mathMixMatFun, gen_inv_test_3) {
29
+ using stan::test::expect_ad;
30
+ using stan::test::expect_ad_matvar;
31
+
32
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
19
33
20
34
Eigen::MatrixXd v (2 , 3 );
21
35
v << 1 , 3 , 5 , 2 , 4 , 6 ;
22
36
expect_ad (f, v);
23
37
expect_ad_matvar (f, v);
38
+ }
39
+
40
+ TEST (mathMixMatFun, gen_inv_test_4) {
41
+ using stan::test::expect_ad;
42
+ using stan::test::expect_ad_matvar;
24
43
44
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
45
+
46
+ Eigen::MatrixXd v (2 , 3 );
25
47
v << 1.9 , 1.3 , 2.5 , 0.4 , 1.7 , 0.1 ;
26
48
expect_ad (f, v);
27
49
expect_ad_matvar (f, v);
50
+ }
51
+
52
+ TEST (mathMixMatFun, gen_inv_test_5) {
53
+ using stan::test::expect_ad;
54
+ using stan::test::expect_ad_matvar;
55
+
56
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
28
57
29
58
Eigen::MatrixXd s (2 , 4 );
30
59
s << 3.4 , 2 , 5 , 1.2 , 2 , 1 , 3.2 , 3.1 ;
31
60
expect_ad (f, s);
32
61
expect_ad_matvar (f, s);
62
+ }
63
+
64
+ TEST (mathMixMatFun, gen_inv_test_6) {
65
+ using stan::test::expect_ad;
66
+ using stan::test::expect_ad_matvar;
67
+
68
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
33
69
34
70
// issues around zero require looser tolerances for hessians
35
71
stan::test::ad_tolerances tols;
@@ -40,10 +76,24 @@ TEST(mathMixMatFun, ad_tests) {
40
76
w << 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 25 , 27 , 29 ;
41
77
expect_ad (tols, f, w);
42
78
expect_ad_matvar (f, w);
79
+ }
80
+
81
+ TEST (mathMixMatFun, gen_inv_test_8) {
82
+ using stan::test::expect_ad;
83
+ using stan::test::expect_ad_matvar;
84
+
85
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
43
86
44
87
Eigen::MatrixXd z (2 , 2 );
45
88
z << 1 , 2 , 5 , std::numeric_limits<double >::quiet_NaN ();
46
89
EXPECT_NO_THROW (stan::math::generalized_inverse (z));
90
+ }
91
+
92
+ TEST (mathMixMatFun, gen_inv_test_9) {
93
+ using stan::test::expect_ad;
94
+ using stan::test::expect_ad_matvar;
95
+
96
+ auto f = [](const auto & G) { return stan::math::generalized_inverse (G); };
47
97
48
98
// autodiff throws, so following fails (throw behavior must match to pass)
49
99
0 commit comments