Stan Math Library  2.20.0
reverse mode automatic differentiation
divide_columns.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_DIVIDE_COLUMNS_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_DIVIDE_COLUMNS_HPP
3 
7 #include <vector>
8 
9 namespace stan {
10 namespace math {
25 template <typename T_x, typename T_v>
26 inline typename std::vector<Eigen::Matrix<
27  typename return_type<T_x, T_v, double>::type, Eigen::Dynamic, 1>>
28 divide_columns(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
29  const std::vector<T_v> &vec) {
30  const size_t N = x.size();
31  const size_t D = x[0].size();
32  check_size_match("divide_columns", "x dimension", D, "vector", vec.size());
33  Eigen::Map<const Eigen::Array<T_v, Eigen::Dynamic, 1>> v_vec(&vec[0],
34  vec.size());
35 
36  std::vector<Eigen::Matrix<typename return_type<T_x, T_v, double>::type,
37  Eigen::Dynamic, 1>>
38  out(N);
39  for (size_t n = 0; n < N; ++n) {
40  out[n].resize(D);
41  check_size_match("divide_columns", "x dimension", x[n].size(), "vector",
42  v_vec.size());
43  out[n] = x[n].array() / v_vec.array();
44  }
45  return out;
46 }
47 } // namespace math
48 } // namespace stan
49 
50 #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.
std::vector< Eigen::Matrix< typename return_type< T_x, T_v, double >::type, Eigen::Dynamic, 1 > > divide_columns(const std::vector< Eigen::Matrix< T_x, Eigen::Dynamic, 1 >> &x, const std::vector< T_v > &vec)
Takes Stan data type vector[n] x[D] and divides column vector in x element-wise by the values in vec...
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

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