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
8#include <vector>
9
10namespace stan {
11namespace math {
12
23template <typename T_x, typename T_v>
24inline typename std::vector<
25 Eigen::Matrix<return_type_t<T_x, T_v, double>, Eigen::Dynamic, 1>>
26divide_columns(const std::vector<Eigen::Matrix<T_x, Eigen::Dynamic, 1>> &x,
27 const std::vector<T_v> &vec) {
28 const size_t N = x.size();
29 const size_t D = x[0].size();
30 check_size_match("divide_columns", "x dimension", D, "vector", vec.size());
31 std::vector<Eigen::Matrix<return_type_t<T_x, T_v, double>, Eigen::Dynamic, 1>>
32 out(N);
33 for (size_t n = 0; n < N; ++n) {
34 out[n].resize(D);
35 check_size_match("divide_columns", "x dimension", x[n].size(), "vector",
36 vec.size());
37 out[n] = x[n].array() / as_array_or_scalar(vec).array();
38 }
39 return out;
40}
41
42} // namespace math
43} // namespace stan
44
45#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
T as_array_or_scalar(T &&v)
Returns specified input value.
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 ...