Automatic Differentiation
 
Loading...
Searching...
No Matches
as_column_vector_or_scalar.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_AS_COLUMN_VECTOR_OR_SCALAR_HPP
2#define STAN_MATH_PRIM_FUN_AS_COLUMN_VECTOR_OR_SCALAR_HPP
3
6#include <vector>
7
8namespace stan {
9namespace math {
10namespace internal {
11template <typename T, typename S, typename Enable>
12class empty_broadcast_array;
13}
21template <typename T, require_stan_scalar_t<T>* = nullptr>
22inline T as_column_vector_or_scalar(const T& a) {
23 return a;
24}
25
31template <typename T, typename S>
34
43template <typename T, require_eigen_col_vector_t<T>* = nullptr>
44inline T&& as_column_vector_or_scalar(T&& a) {
45 return std::forward<T>(a);
46}
47
57template <typename T, require_eigen_row_vector_t<T>* = nullptr,
58 require_not_eigen_col_vector_t<T>* = nullptr>
59inline auto as_column_vector_or_scalar(T&& a) {
60 return make_holder([](auto& x) { return x.transpose(); }, std::forward<T>(a));
61}
62
70template <typename T, require_std_vector_t<T>* = nullptr>
71inline auto as_column_vector_or_scalar(T&& a) {
72 using plain_vector = Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, 1>;
73 using optionally_const_vector
74 = std::conditional_t<std::is_const<std::remove_reference_t<T>>::value,
75 const plain_vector, plain_vector>;
76 using T_map = Eigen::Map<optionally_const_vector>;
77 return make_holder([](auto& x) { return T_map(x.data(), x.size()); },
78 std::forward<T>(a));
79}
80
81} // namespace math
82} // namespace stan
83
84#endif
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
auto make_holder(const F &func, Args &&... args)
Constructs an expression from given arguments using given functor.
Definition holder.hpp:352
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...