Skip to content

Commit ee568be

Browse files
committed
[Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final)
1 parent ac8ab87 commit ee568be

3 files changed

Lines changed: 222 additions & 113 deletions

File tree

stan/math/prim/err/check_flag_sundials.hpp

Lines changed: 218 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -12,128 +12,235 @@ namespace math {
1212
#define CHECK_CVODES_CALL(call) cvodes_check(call, #call)
1313
#define CHECK_KINSOL_CALL(call) kinsol_check(call, #call)
1414

15-
/**
16-
* Map cvodes error flag to acutally error msg. The most frequent
17-
* errors are put at the top. An alternative would be to use std::map
18-
* but in our case the difference would be negligible. Note that we
19-
* don't use CVGetReturnFlagName function to retrieve the constant
20-
* because sanitizer indicates it contains mem leak.
21-
*
22-
* @param flag
23-
*
24-
* @return error msg string constant and actuall informative msg
25-
*/
26-
inline std::array<std::string, 2> cvodes_flag_msg(int flag) {
27-
std::array<std::string, 2> msg;
28-
switch (flag) {
29-
case -1 : msg = {"CV_TOO_MUCH_WORK" , "The solver took mxstep internal steps but could not reach tout"}; break; // NOLINT
30-
case -2 : msg = {"CV_TOO_MUCH_ACC" , "The solver could not satisfy the accuracy demanded by the user for some internal step"}; break; // NOLINT
31-
case -3 : msg = {"CV_ERR_FAILURE" , "Error test failures occurred too many times during one internal time step or minimum step size was reached"}; break; // NOLINT
32-
case -4 : msg = {"CV_CONV_FAILURE" , "Convergence test failures occurred too many times during one internal time step or minimum step size was reached"}; break; // NOLINT
33-
case -8 : msg = {"CV_RHSFUNC_FAIL" , "The right-hand side function failed in an unrecoverable manner"}; break; // NOLINT
34-
case -9 : msg = {"CV_FIRST_RHSFUNC_ERR", "The right-hand side function failed at the first call"}; break; // NOLINT
35-
case -10 : msg = {"CV_REPTD_RHSFUNC_ERR", "The right-hand side function had repetead recoverable errors"}; break; // NOLINT
36-
case -11 : msg = {"CV_UNREC_RHSFUNC_ERR", "The right-hand side function had a recoverable error, but no recovery is possible"}; break; // NOLINT
37-
case -27 : msg = {"CV_TOO_CLOSE" , "The output and initial times are too close to each other"}; break; // NOLINT
15+
/**
16+
* Map cvodes error flag to acutally error msg. The most frequent
17+
* errors are put at the top. An alternative would be to use std::map
18+
* but in our case the difference would be negligible. Note that we
19+
* don't use CVGetReturnFlagName function to retrieve the constant
20+
* because sanitizer indicates it contains mem leak.
21+
*
22+
* @param flag
23+
*
24+
* @return error msg string constant and actuall informative msg
25+
*/
26+
inline std::array<std::string, 2> cvodes_flag_msg(int flag) {
27+
std::array<std::string, 2> msg;
28+
switch (flag) {
29+
case -1:
30+
msg = {"CV_TOO_MUCH_WORK",
31+
"The solver took mxstep internal steps but could not reach tout"};
32+
break; // NOLINT
33+
case -2:
34+
msg = {"CV_TOO_MUCH_ACC",
35+
"The solver could not satisfy the accuracy demanded by the user "
36+
"for some internal step"};
37+
break; // NOLINT
38+
case -3:
39+
msg = {"CV_ERR_FAILURE",
40+
"Error test failures occurred too many times during one internal "
41+
"time step or minimum step size was reached"};
42+
break; // NOLINT
43+
case -4:
44+
msg = {"CV_CONV_FAILURE",
45+
"Convergence test failures occurred too many times during one "
46+
"internal time step or minimum step size was reached"};
47+
break; // NOLINT
48+
case -8:
49+
msg = {"CV_RHSFUNC_FAIL",
50+
"The right-hand side function failed in an unrecoverable manner"};
51+
break; // NOLINT
52+
case -9:
53+
msg = {"CV_FIRST_RHSFUNC_ERR",
54+
"The right-hand side function failed at the first call"};
55+
break; // NOLINT
56+
case -10:
57+
msg = {"CV_REPTD_RHSFUNC_ERR",
58+
"The right-hand side function had repetead recoverable errors"};
59+
break; // NOLINT
60+
case -11:
61+
msg = {"CV_UNREC_RHSFUNC_ERR",
62+
"The right-hand side function had a recoverable error, but no "
63+
"recovery is possible"};
64+
break; // NOLINT
65+
case -27:
66+
msg = {"CV_TOO_CLOSE",
67+
"The output and initial times are too close to each other"};
68+
break; // NOLINT
3869
default:
3970
switch (flag) {
40-
case -5 : msg = {"CV_LINIT_FAIL" , "The linear solver's initialization function failed"}; break; // NOLINT
41-
case -6 : msg = {"CV_LSETUP_FAIL" , "The linear solver's setup function failed in an unrecoverable manner"}; break; // NOLINT
42-
case -7 : msg = {"CV_LSOLVE_FAIL" , "The linear solver's solve function failed in an unrecoverable manner"}; break; // NOLINT
43-
case -20 : msg = {"CV_MEM_FAIL" , "A memory allocation failed"}; break; // NOLINT
44-
case -21 : msg = {"CV_MEM_NULL" , "The cvode_mem argument was NULL"}; break; // NOLINT
45-
case -22 : msg = {"CV_ILL_INPUT" , "One of the function inputs is illegal"}; break; // NOLINT
46-
case -23 : msg = {"CV_NO_MALLOC" , "The CVODE memory block was not allocated by a call to CVodeMalloc"}; break; // NOLINT
47-
case -24 : msg = {"CV_BAD_K" , "The derivative order k is larger than the order used"}; break; // NOLINT
48-
case -25 : msg = {"CV_BAD_T" , "The time t s outside the last step taken"}; break; // NOLINT
49-
case -26 : msg = {"CV_BAD_DKY" , "The output derivative vector is NULL"}; break; // NOLINT
50-
case -40 : msg = {"CV_BAD_IS" , "The sensitivity index is larger than the number of sensitivities computed"}; break; // NOLINT
51-
case -41 : msg = {"CV_NO_SENS" , "Forward sensitivity integration was not activated"}; break; // NOLINT
52-
case -42 : msg = {"CV_SRHSFUNC_FAIL" , "The sensitivity right-hand side function failed in an unrecoverable manner"}; break; // NOLINT
53-
case -43 : msg = {"CV_FIRST_SRHSFUNC_ER", "The sensitivity right-hand side function failed at the first call"}; break; // NOLINT
54-
case -44 : msg = {"CV_REPTD_SRHSFUNC_ER", "The sensitivity ight-hand side function had repetead recoverable errors"}; break; // NOLINT
55-
case -45 : msg = {"CV_UNREC_SRHSFUNC_ER", "The sensitivity right-hand side function had a recoverable error, but no recovery is possible"}; break; // NOLINT
56-
case -101: msg = {"CV_ADJMEM_NULL" , "The cvadj_mem argument was NULL"}; break; // NOLINT
57-
case -103: msg = {"CV_BAD_TB0" , "The final time for the adjoint problem is outside the interval over which the forward problem was solved"}; break; // NOLINT
58-
case -104: msg = {"CV_BCKMEM_NULL" , "The cvodes memory for the backward problem was not created"}; break; // NOLINT
59-
case -105: msg = {"CV_REIFWD_FAIL" , "Reinitialization of the forward problem failed at the first checkpoint"}; break; // NOLINT
60-
case -106: msg = {"CV_FWD_FAIL" , "An error occured during the integration of the forward problem"}; break; // NOLINT
61-
case -107: msg = {"CV_BAD_ITASK" , "Wrong task for backward integration"}; break; // NOLINT
62-
case -108: msg = {"CV_BAD_TBOUT" , "The desired output time is outside the interval over which the forward problem was solved"}; break; // NOLINT
63-
case -109: msg = {"CV_GETY_BADT" , "Wrong time in interpolation function"}; break; // NOLINT
71+
case -5:
72+
msg = {"CV_LINIT_FAIL",
73+
"The linear solver's initialization function failed"};
74+
break; // NOLINT
75+
case -6:
76+
msg = {"CV_LSETUP_FAIL",
77+
"The linear solver's setup function failed in an "
78+
"unrecoverable manner"};
79+
break; // NOLINT
80+
case -7:
81+
msg = {"CV_LSOLVE_FAIL",
82+
"The linear solver's solve function failed in an "
83+
"unrecoverable manner"};
84+
break; // NOLINT
85+
case -20:
86+
msg = {"CV_MEM_FAIL", "A memory allocation failed"};
87+
break; // NOLINT
88+
case -21:
89+
msg = {"CV_MEM_NULL", "The cvode_mem argument was NULL"};
90+
break; // NOLINT
91+
case -22:
92+
msg = {"CV_ILL_INPUT", "One of the function inputs is illegal"};
93+
break; // NOLINT
94+
case -23:
95+
msg = {"CV_NO_MALLOC",
96+
"The CVODE memory block was not allocated by a call to "
97+
"CVodeMalloc"};
98+
break; // NOLINT
99+
case -24:
100+
msg = {"CV_BAD_K",
101+
"The derivative order k is larger than the order used"};
102+
break; // NOLINT
103+
case -25:
104+
msg = {"CV_BAD_T", "The time t s outside the last step taken"};
105+
break; // NOLINT
106+
case -26:
107+
msg = {"CV_BAD_DKY", "The output derivative vector is NULL"};
108+
break; // NOLINT
109+
case -40:
110+
msg = {"CV_BAD_IS",
111+
"The sensitivity index is larger than the number of "
112+
"sensitivities computed"};
113+
break; // NOLINT
114+
case -41:
115+
msg = {"CV_NO_SENS",
116+
"Forward sensitivity integration was not activated"};
117+
break; // NOLINT
118+
case -42:
119+
msg = {"CV_SRHSFUNC_FAIL",
120+
"The sensitivity right-hand side function failed in an "
121+
"unrecoverable manner"};
122+
break; // NOLINT
123+
case -43:
124+
msg = {"CV_FIRST_SRHSFUNC_ER",
125+
"The sensitivity right-hand side function failed at the first "
126+
"call"};
127+
break; // NOLINT
128+
case -44:
129+
msg = {"CV_REPTD_SRHSFUNC_ER",
130+
"The sensitivity ight-hand side function had repetead "
131+
"recoverable errors"};
132+
break; // NOLINT
133+
case -45:
134+
msg = {"CV_UNREC_SRHSFUNC_ER",
135+
"The sensitivity right-hand side function had a recoverable "
136+
"error, but no recovery is possible"};
137+
break; // NOLINT
138+
case -101:
139+
msg = {"CV_ADJMEM_NULL", "The cvadj_mem argument was NULL"};
140+
break; // NOLINT
141+
case -103:
142+
msg = {"CV_BAD_TB0",
143+
"The final time for the adjoint problem is outside the "
144+
"interval over which the forward problem was solved"};
145+
break; // NOLINT
146+
case -104:
147+
msg = {"CV_BCKMEM_NULL",
148+
"The cvodes memory for the backward problem was not created"};
149+
break; // NOLINT
150+
case -105:
151+
msg = {"CV_REIFWD_FAIL",
152+
"Reinitialization of the forward problem failed at the first "
153+
"checkpoint"};
154+
break; // NOLINT
155+
case -106:
156+
msg = {
157+
"CV_FWD_FAIL",
158+
"An error occured during the integration of the forward problem"};
159+
break; // NOLINT
160+
case -107:
161+
msg = {"CV_BAD_ITASK", "Wrong task for backward integration"};
162+
break; // NOLINT
163+
case -108:
164+
msg = {"CV_BAD_TBOUT",
165+
"The desired output time is outside the interval over which "
166+
"the forward problem was solved"};
167+
break; // NOLINT
168+
case -109:
169+
msg = {"CV_GETY_BADT", "Wrong time in interpolation function"};
170+
break; // NOLINT
64171
}
65-
}
66-
return msg;
67-
}
68-
69-
/**
70-
* Throws a std::runtime_error exception when a Sundial function fails
71-
* (i.e. returns a negative flag)
72-
*
73-
* @param flag Error flag
74-
* @param func_name Name of the function that returned the flag
75-
* @throw <code>std::runtime_error</code> if the flag is negative
76-
*/
77-
inline void cvodes_check(int flag, const char* func_name) {
78-
if (flag < 0) {
79-
std::ostringstream ss;
80-
ss << func_name << " failed with error flag " << flag << ": \n"
81-
<< cvodes_flag_msg(flag).at(1) << ".";
82-
if (flag == -1 || flag == -4) {
83-
throw std::domain_error(ss.str());
84-
} else {
85-
throw std::runtime_error(ss.str());
86-
}
87-
}
88172
}
173+
return msg;
174+
}
89175

90-
/**
91-
* Throws an exception message when the functions in KINSOL
92-
* fails. When the exception is caused
93-
* by a tuning parameter the user controls, gives a specific
94-
* error. "KINGetReturnFlagName()" from sundials has a mem leak bug so
95-
* until it's fixed we cannot use it to extract flag error string.
96-
*
97-
* @param flag Error flag
98-
* @param func_name calling function name
99-
* @throw <code>std::runtime_error</code> if the flag is negative.
100-
*/
101-
inline void kinsol_check(int flag, const char* func_name) {
176+
/**
177+
* Throws a std::runtime_error exception when a Sundial function fails
178+
* (i.e. returns a negative flag)
179+
*
180+
* @param flag Error flag
181+
* @param func_name Name of the function that returned the flag
182+
* @throw <code>std::runtime_error</code> if the flag is negative
183+
*/
184+
inline void cvodes_check(int flag, const char* func_name) {
185+
if (flag < 0) {
102186
std::ostringstream ss;
103-
if (flag < 0) {
104-
ss << "algebra_solver failed with error flag " << flag << ".";
187+
ss << func_name << " failed with error flag " << flag << ": \n"
188+
<< cvodes_flag_msg(flag).at(1) << ".";
189+
if (flag == -1 || flag == -4) {
190+
throw std::domain_error(ss.str());
191+
} else {
105192
throw std::runtime_error(ss.str());
106193
}
107194
}
195+
}
108196

109-
/**
110-
* Throws an exception message when the KINSol() call fails.
111-
* When the exception is caused
112-
* by a tuning parameter the user controls, gives a specific
113-
* error.
114-
*
115-
* @param flag Error flag
116-
* @param func_name calling function name
117-
* @param max_num_steps max number of nonlinear iters
118-
* @throw <code>std::runtime_error</code> if the flag is negative.
119-
* @throw <code>std::domain_error</code> if the flag indicates max
120-
* number of steps is exceeded..
121-
*/
122-
inline void kinsol_check(int flag, const char* func_name,
123-
long int max_num_steps) { // NOLINT(runtime/int)
124-
std::ostringstream ss;
125-
if (flag == -6) {
126-
domain_error("algebra_solver", "maximum number of iterations",
127-
max_num_steps, "(", ") was exceeded in the solve.");
128-
} else if (flag == -11) {
129-
ss << "The linear solver’s setup function failed "
130-
<< "in an unrecoverable manner.";
131-
throw std::runtime_error(ss.str());
132-
} else if (flag < 0) {
133-
ss << "algebra_solver failed with error flag " << flag << ".";
134-
throw std::runtime_error(ss.str());
135-
}
197+
/**
198+
* Throws an exception message when the functions in KINSOL
199+
* fails. When the exception is caused
200+
* by a tuning parameter the user controls, gives a specific
201+
* error. "KINGetReturnFlagName()" from sundials has a mem leak bug so
202+
* until it's fixed we cannot use it to extract flag error string.
203+
*
204+
* @param flag Error flag
205+
* @param func_name calling function name
206+
* @throw <code>std::runtime_error</code> if the flag is negative.
207+
*/
208+
inline void kinsol_check(int flag, const char* func_name) {
209+
std::ostringstream ss;
210+
if (flag < 0) {
211+
ss << "algebra_solver failed with error flag " << flag << ".";
212+
throw std::runtime_error(ss.str());
213+
}
214+
}
215+
216+
/**
217+
* Throws an exception message when the KINSol() call fails.
218+
* When the exception is caused
219+
* by a tuning parameter the user controls, gives a specific
220+
* error.
221+
*
222+
* @param flag Error flag
223+
* @param func_name calling function name
224+
* @param max_num_steps max number of nonlinear iters
225+
* @throw <code>std::runtime_error</code> if the flag is negative.
226+
* @throw <code>std::domain_error</code> if the flag indicates max
227+
* number of steps is exceeded..
228+
*/
229+
inline void kinsol_check(int flag, const char* func_name,
230+
long int max_num_steps) { // NOLINT(runtime/int)
231+
std::ostringstream ss;
232+
if (flag == -6) {
233+
domain_error("algebra_solver", "maximum number of iterations",
234+
max_num_steps, "(", ") was exceeded in the solve.");
235+
} else if (flag == -11) {
236+
ss << "The linear solver’s setup function failed "
237+
<< "in an unrecoverable manner.";
238+
throw std::runtime_error(ss.str());
239+
} else if (flag < 0) {
240+
ss << "algebra_solver failed with error flag " << flag << ".";
241+
throw std::runtime_error(ss.str());
136242
}
243+
}
137244

138245
} // namespace math
139246
} // namespace stan

test/unit/math/rev/functor/algebra_solver_newton_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ TEST_F(degenerate_eq_test, newton_guess_saddle_point_dbl) {
9999
// a saddle point.
100100
using stan::math::algebra_solver_newton;
101101
std::stringstream err_msg;
102-
err_msg << "The linear solver’s setup function failed in an unrecoverable manner"; // NOLINT
102+
err_msg << "The linear solver’s setup function failed in an unrecoverable "
103+
"manner"; // NOLINT
103104
std::string msg = err_msg.str();
104105

105106
EXPECT_THROW_MSG(algebra_solver_newton(degenerate_eq_functor(), x_guess_3,

test/unit/math/rev/functor/util_algebra_solver.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ void inline unsolvable_flag_test(Eigen::Matrix<T, Eigen::Dynamic, 1>& y,
426426
std::vector<double> dat;
427427
std::vector<int> dat_int;
428428
std::stringstream err_msg;
429-
err_msg << "The linear solver’s setup function failed in an unrecoverable manner."; // NOLINT
429+
err_msg << "The linear solver’s setup function failed in an unrecoverable "
430+
"manner."; // NOLINT
430431
std::string msg = err_msg.str();
431432
EXPECT_THROW_MSG(general_algebra_solver(is_newton, unsolvable_eq_functor(), x,
432433
y, dat, dat_int),

0 commit comments

Comments
 (0)