@@ -51,8 +51,8 @@ T& algebra_solver_powell_call_solver(const F& f, T& x, std::ostream* const msgs,
51
51
const int64_t max_num_steps,
52
52
const Args&... args) {
53
53
// Construct the solver
54
- hybrj_functor_solver<decltype (f) > hfs (f);
55
- Eigen::HybridNonLinearSolver<decltype (hfs) > solver (hfs);
54
+ hybrj_functor_solver<F > hfs (f);
55
+ Eigen::HybridNonLinearSolver<hybrj_functor_solver<F> > solver (hfs);
56
56
57
57
// Compute theta_dbl
58
58
solver.parameters .xtol = relative_tolerance;
@@ -61,7 +61,7 @@ T& algebra_solver_powell_call_solver(const F& f, T& x, std::ostream* const msgs,
61
61
62
62
// Check if the max number of steps has been exceeded
63
63
if (solver.nfev >= max_num_steps) {
64
- [& ]() STAN_COLD_PATH {
64
+ [max_num_steps ]() STAN_COLD_PATH {
65
65
throw_domain_error (" algebra_solver" , " maximum number of iterations" ,
66
66
max_num_steps, " (" , " ) was exceeded in the solve." );
67
67
}();
@@ -70,7 +70,7 @@ T& algebra_solver_powell_call_solver(const F& f, T& x, std::ostream* const msgs,
70
70
// Check solution is a root
71
71
double system_norm = f (x).stableNorm ();
72
72
if (system_norm > function_tolerance) {
73
- [& ]() STAN_COLD_PATH {
73
+ [function_tolerance, system_norm ]() STAN_COLD_PATH {
74
74
std::ostringstream message;
75
75
message << " the norm of the algebraic function is " << system_norm
76
76
<< " but should be lower than the function "
@@ -132,7 +132,7 @@ Eigen::VectorXd algebra_solver_powell_impl(const F& f, const T& x,
132
132
const double function_tolerance,
133
133
const int64_t max_num_steps,
134
134
const Args&... args) {
135
- plain_type_t < decltype ( to_ref ( value_of (x)))> x_ref = to_ref (value_of (x));
135
+ auto x_ref = eval (value_of (x));
136
136
auto args_vals_tuple = std::make_tuple (to_ref (args)...);
137
137
138
138
auto f_wrt_x = [&args_vals_tuple, &f, msgs](const auto & x) {
@@ -336,13 +336,13 @@ Eigen::Matrix<var, Eigen::Dynamic, 1> algebra_solver_powell_impl(
336
336
const F& f, const T& x, std::ostream* const msgs,
337
337
const double relative_tolerance, const double function_tolerance,
338
338
const int64_t max_num_steps, const T_Args&... args) {
339
- plain_type_t < decltype ( to_ref ( value_of (x)))> x_ref = to_ref (value_of (x));
340
- auto arena_args_tuple = std::make_tuple (to_arena (args)...);
339
+ auto x_ref = eval (value_of (x));
340
+ auto arena_args_tuple = make_chainable_ptr ( std::make_tuple (eval (args)...) );
341
341
auto args_vals_tuple = apply (
342
342
[&](const auto &... args) {
343
343
return std::make_tuple (to_ref (value_of (args))...);
344
344
},
345
- arena_args_tuple);
345
+ * arena_args_tuple);
346
346
347
347
auto f_wrt_x = [&args_vals_tuple, &f, msgs](const auto & x) {
348
348
return apply (
@@ -386,7 +386,7 @@ Eigen::Matrix<var, Eigen::Dynamic, 1> algebra_solver_powell_impl(
386
386
Eigen::VectorXd ret_val = ret.val ();
387
387
auto x_nrad_ = apply (
388
388
[&](const auto &... args) { return eval (f (ret_val, msgs, args...)); },
389
- arena_args_tuple);
389
+ * arena_args_tuple);
390
390
x_nrad_.adj () = eta;
391
391
grad ();
392
392
}
0 commit comments