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>
126Eigen::Matrix<return_type_t<T_shared_param, T_job_param>, Eigen::Dynamic, 1>
127map_rect(const T_shared_param& shared_params,
128 const std::vector<Eigen::Matrix<T_job_param, Eigen::Dynamic, 1>>&
129 job_params,
130 const std::vector<std::vector<double>>& x_r,
131 const std::vector<std::vector<int>>& x_i,
132 std::ostream* msgs = nullptr) {
133 static constexpr const char* function = "map_rect";
134 using return_t = Eigen::Matrix<return_type_t<T_shared_param, T_job_param>,
135 Eigen::Dynamic, 1>;
136
137 check_matching_sizes(function, "job parameters", job_params, "real data",
138 x_r);
139 check_matching_sizes(function, "job parameters", job_params, "int data", x_i);
140
141 // check size consistency of inputs per job
142 const std::vector<int> job_params_dims = dims(job_params);
143
144 if (job_params_dims[0] == 0) {
145 return return_t();
146 }
147
148 const int size_job_params = job_params_dims[1];
149 const int size_x_r = dims(x_r)[1];
150 const int size_x_i = dims(x_i)[1];
151 for (int i = 1; i < job_params_dims[0]; i++) {
152 check_size_match(function,
153 "Size of one of the vectors of "
154 "the job specific parameters",
155 job_params[i].size(),
156 "size of another vector of the "
157 "job specific parameters",
158 size_job_params);
159 check_size_match(function,
160 "Size of one of the arrays of "
161 "the job specific real data",
162 x_r[i].size(),
163 "size of another array of the "
164 "job specific real data",
165 size_x_r);
166 check_size_match(function,
167 "Size of one of the arrays of "
168 "the job specific int data",
169 x_i[i].size(),
170 "size of another array of the "
171 "job specific int data",
172 size_x_i);
173 }
174
175#ifdef STAN_MPI
176 using T_plain_shared_param = plain_type_t<T_shared_param>;
177 T_plain_shared_param shared_params_eval = shared_params;
178 return internal::map_rect_mpi<call_id, F, T_plain_shared_param, T_job_param>(
179 shared_params_eval, job_params, x_r, x_i, msgs);
180#else
181 using T_shared_param_ref = ref_type_t<T_shared_param>;
182 T_shared_param_ref shared_params_ref = shared_params;
183 return internal::map_rect_concurrent<call_id, F, T_shared_param_ref,
184 T_job_param>(shared_params_ref,
185 job_params, x_r, x_i, msgs);
186#endif
187}
188
189} // namespace math
190} // namespace stan
191
192#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
size_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:18
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:127
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 plain_type< T >::type plain_type_t
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9