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

     [ Stan Home Page ] © 2011–2018, Stan Development Team.