@@ -9,7 +9,7 @@ namespace stan {
99namespace math {
1010
1111namespace internal {
12- /* *
12+ /* *
1313 * Set all adjoints of the output to zero.
1414 */
1515template <typename Output>
@@ -43,8 +43,7 @@ inline void set_zero_adjoint(Output&& output) {
4343 }
4444}
4545
46- }
47-
46+ } // namespace internal
4847
4948/* *
5049 * functions to compute the log density, first, second,
@@ -160,8 +159,7 @@ inline auto shallow_copy_vargs(Args&&... args) {
160159 */
161160template <typename F, typename Theta, typename Stream, typename ... Args,
162161 require_eigen_vector_vt<std::is_arithmetic, Theta>* = nullptr >
163- inline auto theta_grad (F&& f, Theta&& theta,
164- Stream* msgs, Args&&... args) {
162+ inline auto theta_grad (F&& f, Theta&& theta, Stream* msgs, Args&&... args) {
165163 using Eigen::Dynamic;
166164 using Eigen::Matrix;
167165 nested_rev_autodiff nested;
@@ -186,16 +184,14 @@ inline auto theta_grad(F&& f, Theta&& theta,
186184 */
187185template <typename F, typename Theta, typename Stream, typename ... Args,
188186 require_eigen_vector_vt<std::is_arithmetic, Theta>* = nullptr >
189- inline void ll_arg_grad (F&& f, Theta&& theta,
190- Stream* msgs, Args&&... args) {
187+ inline void ll_arg_grad (F&& f, Theta&& theta, Stream* msgs, Args&&... args) {
191188 using Eigen::Dynamic;
192189 using Eigen::Matrix;
193190 nested_rev_autodiff nested;
194191 var f_var = f (theta, args..., msgs);
195192 grad (f_var.vi_ );
196193}
197194
198-
199195/* *
200196 * Computes negative block diagonal Hessian of `f` wrt`theta` and `args...`
201197 * @note If `Args` contains \ref var types then their adjoints will be
@@ -214,14 +210,15 @@ inline void ll_arg_grad(F&& f, Theta&& theta,
214210 */
215211template <typename F, typename Theta, typename Stream, typename ... Args,
216212 require_eigen_vector_vt<std::is_arithmetic, Theta>* = nullptr >
217- inline auto diagonal_hessian (F&& f, Theta&& theta, Stream* msgs, Args&&... args) {
213+ inline auto diagonal_hessian (F&& f, Theta&& theta, Stream* msgs,
214+ Args&&... args) {
218215 using Eigen::Dynamic;
219216 using Eigen::Matrix;
220217 const Eigen::Index theta_size = theta.size ();
221218 auto v = Eigen::VectorXd::Ones (theta_size);
222219 Eigen::VectorXd hessian_v = Eigen::VectorXd::Zero (theta_size);
223220 hessian_times_vector (f, hessian_v, std::forward<Theta>(theta), std::move (v),
224- value_of (args)..., msgs);
221+ value_of (args)..., msgs);
225222 return (-hessian_v).eval ();
226223}
227224
@@ -243,8 +240,9 @@ inline auto diagonal_hessian(F&& f, Theta&& theta, Stream* msgs, Args&&... args)
243240 */
244241template <typename F, typename Theta, typename Stream, typename ... Args,
245242 require_eigen_vector_vt<std::is_arithmetic, Theta>* = nullptr >
246- inline auto block_hessian (F&& f, Theta&& theta, const Eigen::Index hessian_block_size,
247- Stream* msgs, Args&&... args) {
243+ inline auto block_hessian (F&& f, Theta&& theta,
244+ const Eigen::Index hessian_block_size, Stream* msgs,
245+ Args&&... args) {
248246 using Eigen::Dynamic;
249247 using Eigen::Matrix;
250248 const Eigen::Index theta_size = theta.size ();
@@ -260,12 +258,12 @@ inline auto block_hessian(F&& f, Theta&& theta, const Eigen::Index hessian_block
260258 }
261259 return (-hessian_theta).eval ();
262260 } else {
263- return (-hessian_block_diag (f, std::forward<Theta>(theta), hessian_block_size,
264- value_of (args)..., msgs)).eval ();
261+ return (-hessian_block_diag (f, std::forward<Theta>(theta),
262+ hessian_block_size, value_of (args)..., msgs))
263+ .eval ();
265264 }
266265}
267266
268-
269267/* *
270268 * Computes theta gradient and negative block diagonal Hessian of `f` wrt
271269 * `theta` and `args...`
@@ -476,28 +474,27 @@ template <typename F, typename Theta, typename TupleArgs, typename Stream,
476474 require_eigen_vector_t <Theta>* = nullptr ,
477475 require_tuple_t <TupleArgs>* = nullptr >
478476inline auto theta_grad (F&& f, Theta&& theta, TupleArgs&& ll_tup,
479- Stream* msgs = nullptr ) {
477+ Stream* msgs = nullptr ) {
480478 return apply (
481479 [](auto && f, auto && theta, auto && msgs, auto &&... args) {
482- return internal::theta_grad (
483- std::forward< decltype (f)>(f), std::forward<decltype (theta)>(theta),
484- msgs, std::forward<decltype (args)>(args)...);
480+ return internal::theta_grad (std::forward< decltype (f)>(f),
481+ std::forward<decltype (theta)>(theta), msgs ,
482+ std::forward<decltype (args)>(args)...);
485483 },
486484 std::forward<TupleArgs>(ll_tup), std::forward<F>(f),
487485 std::forward<Theta>(theta), msgs);
488486}
489487
490-
491488template <typename F, typename Theta, typename TupleArgs, typename Stream,
492489 require_eigen_vector_t <Theta>* = nullptr ,
493490 require_tuple_t <TupleArgs>* = nullptr >
494491inline auto ll_arg_grad (F&& f, Theta&& theta, TupleArgs&& ll_tup,
495- Stream* msgs = nullptr ) {
492+ Stream* msgs = nullptr ) {
496493 return apply (
497494 [](auto && f, auto && theta, auto && msgs, auto &&... args) {
498- return internal::ll_arg_grad (
499- std::forward< decltype (f)>(f), std::forward<decltype (theta)>(theta),
500- msgs, std::forward<decltype (args)>(args)...);
495+ return internal::ll_arg_grad (std::forward< decltype (f)>(f),
496+ std::forward<decltype (theta)>(theta), msgs ,
497+ std::forward<decltype (args)>(args)...);
501498 },
502499 std::forward<TupleArgs>(ll_tup), std::forward<F>(f),
503500 std::forward<Theta>(theta), msgs);
@@ -506,10 +503,10 @@ inline auto ll_arg_grad(F&& f, Theta&& theta, TupleArgs&& ll_tup,
506503template <typename F, typename Theta, typename TupleArgs, typename Stream,
507504 require_eigen_vector_t <Theta>* = nullptr ,
508505 require_tuple_t <TupleArgs>* = nullptr >
509- inline auto diagonal_hessian (F&& f, Theta&& theta, TupleArgs&& ll_tuple, Stream* msgs) {
506+ inline auto diagonal_hessian (F&& f, Theta&& theta, TupleArgs&& ll_tuple,
507+ Stream* msgs) {
510508 return apply (
511- [](auto && f, auto && theta, auto * msgs,
512- auto &&... args) {
509+ [](auto && f, auto && theta, auto * msgs, auto &&... args) {
513510 return internal::diagonal_hessian (
514511 std::forward<decltype (f)>(f), std::forward<decltype (theta)>(theta),
515512 msgs, std::forward<decltype (args)>(args)...);
@@ -521,8 +518,9 @@ inline auto diagonal_hessian(F&& f, Theta&& theta, TupleArgs&& ll_tuple, Stream*
521518template <typename F, typename Theta, typename TupleArgs, typename Stream,
522519 require_eigen_vector_t <Theta>* = nullptr ,
523520 require_tuple_t <TupleArgs>* = nullptr >
524- inline auto block_hessian (F&& f, Theta&& theta, const Eigen::Index hessian_block_size,
525- TupleArgs&& ll_tuple, Stream* msgs) {
521+ inline auto block_hessian (F&& f, Theta&& theta,
522+ const Eigen::Index hessian_block_size,
523+ TupleArgs&& ll_tuple, Stream* msgs) {
526524 return apply (
527525 [](auto && f, auto && theta, auto hessian_block_size, auto * msgs,
528526 auto &&... args) {
0 commit comments