map_rect_reduce.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUNCTOR_MAP_RECT_REDUCE_HPP
2 #define STAN_MATH_PRIM_MAT_FUNCTOR_MAP_RECT_REDUCE_HPP
3 
5 
6 #include <vector>
7 
8 namespace stan {
9 namespace math {
10 namespace internal {
11 
12 /* Base template class for the reduce step of map_rect.
13  *
14  * This class wraps the user functor F which is executed with a shared
15  * parameter vector and job specific parameters, real and int data.
16  *
17  * The class exposes a double only signature for all inputs while the
18  * template parameters determine what the client code is actually
19  * expecting to be calculated. So whenever T_shared_param or/and
20  * T_job_param correspond to an autodiff type then the respective
21  * gradients are calculated.
22  *
23  * The defined functor always returns a matrix of type double. Each
24  * column correspond to an output of the function which can return
25  * multiple outputs per given input. The rows of this returned matrix
26  * contain the gradients wrt to the shared and/or job specific
27  * parameters (in this order).
28  *
29  * No higher order output format is defined yet.
30  *
31  * @tparam F user functor
32  * @tparam T_shared_param type of shared parameters
33  * @tparam T_job_param type of job specific parameters
34  */
35 template <typename F, typename T_shared_param, typename T_job_param>
36 class map_rect_reduce {};
37 
38 template <typename F>
39 class map_rect_reduce<F, double, double> {
40  public:
41  matrix_d operator()(const vector_d& shared_params,
42  const vector_d& job_specific_params,
43  const std::vector<double>& x_r,
44  const std::vector<int>& x_i,
45  std::ostream* msgs = nullptr) const {
46  return F()(shared_params, job_specific_params, x_r, x_i, msgs).transpose();
47  }
48 };
49 
50 } // namespace internal
51 } // namespace math
52 } // namespace stan
53 
54 #endif
#define F(x, y, z)
Eigen::Matrix< double, Eigen::Dynamic, 1 > vector_d
Definition: typedefs.hpp:24
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > matrix_d
Definition: typedefs.hpp:19
matrix_d operator()(const vector_d &shared_params, const vector_d &job_specific_params, const std::vector< double > &x_r, const std::vector< int > &x_i, std::ostream *msgs=nullptr) const
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:10