@@ -24,6 +24,30 @@ TEST(ErrorHandlingArr, CheckFinite_Vector) {
2424 << " check_finite should throw exception on NaN" ;
2525}
2626
27+ TEST (ErrorHandlingArr, CheckFinite_std_vector_std_vector) {
28+ using stan::math::check_finite;
29+ const char * function = " check_finite" ;
30+ std::vector<double > x = {-1 , 0 , 1 };
31+ std::vector<std::vector<double >> xx = {x};
32+ ASSERT_NO_THROW (check_finite (function, " x" , xx))
33+ << " check_finite should be true with finite x" ;
34+
35+ x = {-1 , 0 , std::numeric_limits<double >::infinity ()};
36+ xx = {x};
37+ EXPECT_THROW (check_finite (function, " x" , xx), std::domain_error)
38+ << " check_finite should throw exception on Inf" ;
39+
40+ x = {-1 , 0 , -std::numeric_limits<double >::infinity ()};
41+ xx = {x};
42+ EXPECT_THROW (check_finite (function, " x" , xx), std::domain_error)
43+ << " check_finite should throw exception on -Inf" ;
44+
45+ x = {-1 , 0 , std::numeric_limits<double >::quiet_NaN ()};
46+ xx = {x};
47+ EXPECT_THROW (check_finite (function, " x" , xx), std::domain_error)
48+ << " check_finite should throw exception on NaN" ;
49+ }
50+
2751TEST (ErrorHandlingArr, CheckFinite_nan) {
2852 using stan::math::check_finite;
2953 const char * function = " check_finite" ;
@@ -94,26 +118,20 @@ TEST(ErrorHandlingMat, CheckFinite_std_vector_Matrix) {
94118
95119 x.resize (3 );
96120 x << -1 , 0 , std::numeric_limits<double >::infinity ();
97-
98- std::vector<Eigen::Matrix<double , Eigen::Dynamic, 1 >> xvi = {x};
99-
100- EXPECT_THROW (check_finite (function, " x" , xvi), std::domain_error)
121+ xv = {x};
122+ EXPECT_THROW (check_finite (function, " x" , xv), std::domain_error)
101123 << " check_finite should throw exception on Inf" ;
102124
103125 x.resize (3 );
104126 x << -1 , 0 , -std::numeric_limits<double >::infinity ();
105-
106- std::vector<Eigen::Matrix<double , Eigen::Dynamic, 1 >> nxvi = {x};
107-
108- EXPECT_THROW (check_finite (function, " x" , nxvi), std::domain_error)
127+ xv = {x};
128+ EXPECT_THROW (check_finite (function, " x" , xv), std::domain_error)
109129 << " check_finite should throw exception on -Inf" ;
110130
111131 x.resize (3 );
112132 x << -1 , 0 , std::numeric_limits<double >::quiet_NaN ();
113-
114- std::vector<Eigen::Matrix<double , Eigen::Dynamic, 1 >> xvn = {x};
115-
116- EXPECT_THROW (check_finite (function, " x" , xvn), std::domain_error)
133+ xv = {x};
134+ EXPECT_THROW (check_finite (function, " x" , xv), std::domain_error)
117135 << " check_finite should throw exception on NaN" ;
118136}
119137
0 commit comments