Stan Math Library  2.20.0
reverse mode automatic differentiation
map_rect.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUNCTOR_MAP_RECT_HPP
2 #define STAN_MATH_PRIM_MAT_FUNCTOR_MAP_RECT_HPP
3 
8 
9 #define STAN_REGISTER_MAP_RECT(CALLID, FUNCTOR)
10 
11 #ifdef STAN_MPI
13 #else
15 #endif
16 
17 #include <vector>
18 
19 namespace stan {
20 namespace math {
21 
120 template <int call_id, typename F, typename T_shared_param,
121  typename T_job_param>
122 Eigen::Matrix<typename stan::return_type<T_shared_param, T_job_param>::type,
123  Eigen::Dynamic, 1>
124 map_rect(const Eigen::Matrix<T_shared_param, Eigen::Dynamic, 1>& shared_params,
125  const std::vector<Eigen::Matrix<T_job_param, Eigen::Dynamic, 1>>&
126  job_params,
127  const std::vector<std::vector<double>>& x_r,
128  const std::vector<std::vector<int>>& x_i,
129  std::ostream* msgs = nullptr) {
130  static const char* function = "map_rect";
131  typedef Eigen::Matrix<
133  Eigen::Dynamic, 1>
134  return_t;
135 
136  check_matching_sizes(function, "job parameters", job_params, "real data",
137  x_r);
138  check_matching_sizes(function, "job parameters", job_params, "int data", x_i);
139 
140  // check size consistency of inputs per job
141  const std::vector<int> job_params_dims = dims(job_params);
142  const int size_job_params = job_params_dims[1];
143  const int size_x_r = dims(x_r)[1];
144  const int size_x_i = dims(x_i)[1];
145  for (int i = 1; i < job_params_dims[0]; i++) {
146  check_size_match(function,
147  "Size of one of the vectors of "
148  "the job specific parameters",
149  job_params[i].size(),
150  "size of another vector of the "
151  "job specifc parameters",
152  size_job_params);
153  check_size_match(function,
154  "Size of one of the arrays of "
155  "the job specific real data",
156  x_r[i].size(),
157  "size of another array of the "
158  "job specifc real data",
159  size_x_r);
160  check_size_match(function,
161  "Size of one of the arrays of "
162  "the job specific int data",
163  x_i[i].size(),
164  "size of another array of the "
165  "job specifc int data",
166  size_x_i);
167  }
168 
169  if (job_params_dims[0] == 0)
170  return return_t();
171 
172 #ifdef STAN_MPI
173  return internal::map_rect_mpi<call_id, F, T_shared_param, T_job_param>(
174  shared_params, job_params, x_r, x_i, msgs);
175 #else
176  return internal::map_rect_concurrent<call_id, F, T_shared_param, T_job_param>(
177  shared_params, job_params, x_r, x_i, msgs);
178 #endif
179 }
180 
181 } // namespace math
182 } // namespace stan
183 
184 #endif
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
void dims(const T &x, std::vector< int > &result)
Definition: dims.hpp:11
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
Definition: return_type.hpp:36
int size(const std::vector< T > &x)
Return the size of the specified standard vector.
Definition: size.hpp:17
void check_matching_sizes(const char *function, const char *name1, const T_y1 &y1, const char *name2, const T_y2 &y2)
Check if two structures at the same size.
Eigen::Matrix< typename stan::return_type< T_shared_param, T_job_param >::type, Eigen::Dynamic, 1 > map_rect(const Eigen::Matrix< T_shared_param, Eigen::Dynamic, 1 > &shared_params, const std::vector< Eigen::Matrix< T_job_param, Eigen::Dynamic, 1 >> &job_params, const std::vector< std::vector< double >> &x_r, const std::vector< std::vector< int >> &x_i, std::ostream *msgs=nullptr)
Map N function evaluations to parameters and data which are in rectangular format.
Definition: map_rect.hpp:124

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