Stan Math Library  2.20.0
reverse mode automatic differentiation
as_array_or_scalar.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_AS_ARRAY_OR_SCALAR_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_AS_ARRAY_OR_SCALAR_HPP
3 
5 #include <vector>
6 
7 namespace stan {
8 namespace math {
9 
19 template <typename T, int R, int C>
20 inline Eigen::ArrayWrapper<const Eigen::Matrix<T, R, C>> as_array_or_scalar(
21  const Eigen::Matrix<T, R, C>& v) {
22  return v.array();
23 }
24 
34 template <typename T, int R, int C>
35 inline Eigen::ArrayWrapper<const Eigen::Map<const Eigen::Matrix<T, R, C>>>
36 as_array_or_scalar(const Eigen::Map<const Eigen::Matrix<T, R, C>>& v) {
37  return v.array();
38 }
39 
47 template <typename T>
48 inline Eigen::Map<const Eigen::Array<T, Eigen::Dynamic, 1>> as_array_or_scalar(
49  const std::vector<T>& v) {
50  return Eigen::Map<const Eigen::Array<T, Eigen::Dynamic, 1>>(v.data(),
51  v.size());
52 }
53 
54 } // namespace math
55 } // namespace stan
56 
57 #endif
Eigen::ArrayWrapper< const Eigen::Matrix< T, R, C > > as_array_or_scalar(const Eigen::Matrix< T, R, C > &v)
Converts a matrix type to an array.

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