Automatic Differentiation
 
Loading...
Searching...
No Matches
divide_columns.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_DIVIDE_COLUMNS_HPP
2#define STAN_MATH_PRIM_FUN_DIVIDE_COLUMNS_HPP
3
7#include <vector>
8
9namespace stan {
10namespace math {
11
22template <typename T_x, typename T_v>
23inline typename std::vector<
24 Eigen::Matrix<return_type_t<T_x, T_v, double>, Eigen::Dynamic, 1>>
25divide_columns(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
26 const std::vector<T_v> &vec) {
27 const size_t N = x.size();
28 const size_t D = x[0].size();
29 check_size_match("divide_columns", "x dimension", D, "vector", vec.size());
30 Eigen::Map<const Eigen::Array<T_v, Eigen::Dynamic, 1>> v_vec(&vec[0],
31 vec.size());
32
33 std::vector<Eigen::Matrix<return_type_t<T_x, T_v, double>, Eigen::Dynamic, 1>>
34 out(N);
35 for (size_t n = 0; n < N; ++n) {
36 out[n].resize(D);
37 check_size_match("divide_columns", "x dimension", x[n].size(), "vector",
38 v_vec.size());
39 out[n] = x[n].array() / v_vec.array();
40 }
41 return out;
42}
43
44} // namespace math
45} // namespace stan
46
47#endif
void divide_columns(matrix_cl< T1 > &A, const matrix_cl< T2 > &B)
Divides each column of a matrix by a vector.
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
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.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...