Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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(); },
61 std::forward<T>(a));
62}
63
71template <typename T, require_std_vector_t<T>* = nullptr>
72inline auto as_column_vector_or_scalar(T&& a) {
73 using plain_vector = Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, 1>;
74 using optionally_const_vector
75 = std::conditional_t<std::is_const<std::remove_reference_t<T>>::value,
76 const plain_vector, plain_vector>;
77 using T_map = Eigen::Map<optionally_const_vector>;
78 return make_holder([](auto&& x) { return T_map(x.data(), x.size()); },
79 std::forward<T>(a));
80}
81
82} // namespace math
83} // namespace stan
84
85#endif
auto as_column_vector_or_scalar(T &&a)
as_column_vector_or_scalar of a kernel generator expression.
auto make_holder(F &&func, Args &&... args)
Constructs an expression from given arguments using given functor.
Definition holder.hpp:368
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...