Automatic Differentiation
 
Loading...
Searching...
No Matches
to_row_vector.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_TO_ROW_VECTOR_HPP
2#define STAN_MATH_PRIM_FUN_TO_ROW_VECTOR_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
11// row_vector to_row_vector(matrix)
12// row_vector to_row_vector(vector)
13// row_vector to_row_vector(row_vector)
14template <typename EigMat, require_eigen_t<EigMat>* = nullptr>
15inline Eigen::Matrix<value_type_t<EigMat>, 1, Eigen::Dynamic> to_row_vector(
16 const EigMat& matrix) {
17 using T = value_type_t<EigMat>;
18 Eigen::Matrix<T, 1, Eigen::Dynamic> res(matrix.size());
19 Eigen::Map<
20 Eigen::Matrix<T, EigMat::RowsAtCompileTime, EigMat::ColsAtCompileTime>>
21 res_map(res.data(), matrix.rows(), matrix.cols());
22 res_map = matrix;
23 return res;
24}
25
26// row_vector to_row_vector(real[])
27template <typename T>
28inline Eigen::Matrix<T, 1, Eigen::Dynamic> to_row_vector(
29 const std::vector<T>& vec) {
30 return Eigen::Matrix<T, 1, Eigen::Dynamic>::Map(vec.data(), vec.size());
31}
32
33// row_vector to_row_vector(int[])
34inline Eigen::Matrix<double, 1, Eigen::Dynamic> to_row_vector(
35 const std::vector<int>& vec) {
36 int C = vec.size();
37 Eigen::Matrix<double, 1, Eigen::Dynamic> result(C);
38 for (int i = 0; i < C; i++) {
39 result(i) = vec[i];
40 }
41 return result;
42}
43
44} // namespace math
45} // namespace stan
46#endif
auto to_row_vector(T_x &&x)
Returns input matrix reshaped into a row vector.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...