Automatic Differentiation
 
Loading...
Searching...
No Matches
map_rect.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUNCTOR_MAP_RECT_HPP
2#define STAN_MATH_PRIM_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
19namespace stan {
20namespace math {
21
123template <int call_id, typename F, typename T_shared_param,
124 typename T_job_param,
125 require_eigen_col_vector_t<T_shared_param>* = nullptr>
126inline Eigen::Matrix<return_type_t<T_shared_param, T_job_param>, Eigen::Dynamic,
127 1>
128map_rect(const T_shared_param& shared_params,
129 const std::vector<Eigen::Matrix<T_job_param, Eigen::Dynamic, 1>>&
130 job_params,
131 const std::vector<std::vector<double>>& x_r,
132 const std::vector<std::vector<int>>& x_i,
133 std::ostream* msgs = nullptr) {
134 static constexpr const char* function = "map_rect";
135 using return_t = Eigen::Matrix<return_type_t<T_shared_param, T_job_param>,
136 Eigen::Dynamic, 1>;
137
138 check_matching_sizes(function, "job parameters", job_params, "real data",
139 x_r);
140 check_matching_sizes(function, "job parameters", job_params, "int data", x_i);
141
142 // check size consistency of inputs per job
143 const std::vector<int> job_params_dims = dims(job_params);
144
145 if (job_params_dims[0] == 0) {
146 return return_t();
147 }
148
149 const int size_job_params = job_params_dims[1];
150 const int size_x_r = dims(x_r)[1];
151 const int size_x_i = dims(x_i)[1];
152 for (int i = 1; i < job_params_dims[0]; i++) {
153 check_size_match(function,
154 "Size of one of the vectors of "
155 "the job specific parameters",
156 job_params[i].size(),
157 "size of another vector of the "
158 "job specific parameters",
159 size_job_params);
160 check_size_match(function,
161 "Size of one of the arrays of "
162 "the job specific real data",
163 x_r[i].size(),
164 "size of another array of the "
165 "job specific real data",
166 size_x_r);
167 check_size_match(function,
168 "Size of one of the arrays of "
169 "the job specific int data",
170 x_i[i].size(),
171 "size of another array of the "
172 "job specific int data",
173 size_x_i);
174 }
175
176#ifdef STAN_MPI
177 using T_plain_shared_param = plain_type_t<T_shared_param>;
178 T_plain_shared_param shared_params_eval = shared_params;
179 return internal::map_rect_mpi<call_id, F, T_plain_shared_param, T_job_param>(
180 shared_params_eval, job_params, x_r, x_i, msgs);
181#else
182 using T_shared_param_ref = ref_type_t<T_shared_param>;
183 T_shared_param_ref shared_params_ref = shared_params;
184 return internal::map_rect_concurrent<call_id, F, T_shared_param_ref,
185 T_job_param>(shared_params_ref,
186 job_params, x_r, x_i, msgs);
187#endif
188}
189
190} // namespace math
191} // namespace stan
192
193#endif
void dims(const T_x &x, std::vector< int > &result)
matrix_cl overload of the dims helper function in prim/fun/dims.hpp.
Definition dims.hpp:21
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
Eigen::Matrix< return_type_t< T_shared_param, T_job_param >, Eigen::Dynamic, 1 > map_rect_concurrent(const T_shared_param &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)
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< return_type_t< T_shared_param, T_job_param >, Eigen::Dynamic, 1 > map_rect(const T_shared_param &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:128
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.
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:56
typename plain_type< std::decay_t< T > >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...