Stan Math Library  2.20.0
reverse mode automatic differentiation
as_column_vector_or_scalar.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_AS_COLUMN_VECTOR_OR_SCALAR_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_AS_COLUMN_VECTOR_OR_SCALAR_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8 namespace math {
9 
18 template <typename T>
19 inline const Eigen::Matrix<T, Eigen::Dynamic, 1>& as_column_vector_or_scalar(
20  const Eigen::Matrix<T, Eigen::Dynamic, 1>& a) {
21  return a;
22 }
23 
32 template <typename T>
33 inline Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>>
34 as_column_vector_or_scalar(const Eigen::Matrix<T, 1, Eigen::Dynamic>& a) {
35  return Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>>(
36  a.data(), a.size()); // uses Eigen::Map instead of .transpose() so that
37  // there are less possible output types
38 }
39 
48 template <typename T>
49 inline Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>>
50 as_column_vector_or_scalar(const std::vector<T>& a) {
51  return Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>>(a.data(),
52  a.size());
53 }
54 
55 } // namespace math
56 } // namespace stan
57 
58 #endif
const Eigen::Matrix< T, Eigen::Dynamic, 1 > & as_column_vector_or_scalar(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &a)
Converts input argument to a column vector or a scalar.

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