Automatic Differentiation
 
Loading...
Searching...
No Matches
to_array_2d.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_TO_ARRAY_2D_HPP
2#define STAN_MATH_PRIM_FUN_TO_ARRAY_2D_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10
11// real[, ] to_array_2d(matrix)
12template <typename EigMat, require_eigen_t<EigMat>* = nullptr>
13inline std::vector<std::vector<value_type_t<EigMat>>> to_array_2d(
14 const EigMat& matrix) {
15 using std::vector;
16 using T = value_type_t<EigMat>;
17 const Eigen::Ref<const Eigen::Matrix<T, EigMat::RowsAtCompileTime,
18 EigMat::ColsAtCompileTime>>& mat_ref
19 = matrix;
20 int C = matrix.cols();
21 int R = matrix.rows();
22 vector<vector<T>> result(R, vector<T>(C));
23 for (int i = 0, ij = 0; i < C; i++) {
24 for (int j = 0; j < R; j++, ij++) {
25 result[j][i] = mat_ref.data()[ij];
26 }
27 }
28 return result;
29}
30
31} // namespace math
32} // namespace stan
33#endif
T_x to_array_2d(T_x &&x)
Returns input matrix converted into a nested std 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 ...
Definition fvar.hpp:9