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
scalar_seq_view.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SCALAR_SEQ_VIEW_HPP
2#define STAN_MATH_PRIM_FUN_SCALAR_SEQ_VIEW_HPP
3
6#include <type_traits>
7#include <utility>
8
9namespace stan {
17template <typename C, typename = void>
19
20template <typename C>
22 public:
23 template <typename T,
25 explicit scalar_seq_view(T&& c) : c_(std::forward<T>(c)) {}
26
32 inline auto operator[](size_t i) const { return c_.coeff(i); }
33
34 inline auto size() const noexcept { return c_.size(); }
35
36 inline const value_type_t<C>* data() const noexcept { return c_.data(); }
37 inline value_type_t<C>* data() noexcept { return c_.data(); }
38
39 template <typename T = C, require_st_arithmetic<T>* = nullptr>
40 inline decltype(auto) val(size_t i) const {
41 return c_.coeffRef(i);
42 }
43
44 template <typename T = C, require_st_autodiff<T>* = nullptr>
45 inline decltype(auto) val(size_t i) const {
46 return c_.coeffRef(i).val();
47 }
48
49 private:
51};
52
53template <typename C>
55 public:
56 template <typename T,
58 explicit scalar_seq_view(T&& c) : c_(std::forward<T>(c)) {}
59
65 inline auto operator[](size_t i) const { return c_.coeff(i); }
66 inline const auto* data() const noexcept { return c_.vi_; }
67 inline auto* data() noexcept { return c_.vi_; }
68
69 inline auto size() const noexcept { return c_.size(); }
70
71 template <typename T = C, require_st_autodiff<T>* = nullptr>
72 inline auto val(size_t i) const {
73 return c_.val().coeff(i);
74 }
75
76 template <typename T = C, require_st_autodiff<T>* = nullptr>
77 inline auto& val(size_t i) {
78 return c_.val().coeffRef(i);
79 }
80
81 private:
82 std::decay_t<C> c_;
83};
84
85template <typename C>
87 public:
88 template <typename T,
90 explicit scalar_seq_view(T&& c) : c_(std::forward<T>(c)) {}
91
97 inline auto operator[](size_t i) const { return c_[i]; }
98 inline auto size() const noexcept { return c_.size(); }
99 inline const auto* data() const noexcept { return c_.data(); }
100
101 template <typename T = C, require_st_arithmetic<T>* = nullptr>
102 inline decltype(auto) val(size_t i) const {
103 return c_[i];
104 }
105
106 template <typename T = C, require_st_autodiff<T>* = nullptr>
107 inline decltype(auto) val(size_t i) const {
108 return c_[i].val();
109 }
110
111 private:
112 const C& c_;
113};
114
115template <typename C>
116class scalar_seq_view<C, require_t<std::is_pointer<C>>> {
117 public:
118 template <typename T,
120 explicit scalar_seq_view(const T& c) : c_(c) {}
121
127 inline auto operator[](size_t i) const { return c_[i]; }
128 inline auto size() const noexcept {
129 static_assert(sizeof(std::decay_t<C>*) == 0,
130 "Cannot Return Size of scalar_seq_view with pointer type");
131 }
132 inline const auto* data() const noexcept { return &c_[0]; }
133
134 template <typename T = C, require_st_arithmetic<T>* = nullptr>
135 inline decltype(auto) val(size_t i) const {
136 return c_[i];
137 }
138
139 template <typename T = C, require_st_autodiff<T>* = nullptr>
140 inline decltype(auto) val(size_t i) const {
141 return c_[i].val();
142 }
143
144 private:
145 const C& c_;
146};
147
153template <typename C>
155 public:
156 explicit scalar_seq_view(const C& t) noexcept : t_(t) {}
157
158 inline decltype(auto) operator[](int /* i */) const noexcept { return t_; }
159
160 template <typename T = C, require_st_arithmetic<T>* = nullptr>
161 inline decltype(auto) val(int /* i */) const noexcept {
162 return t_;
163 }
164
165 template <typename T = C, require_st_autodiff<T>* = nullptr>
166 inline decltype(auto) val(int /* i */) const noexcept {
167 return t_.val();
168 }
169
170 static constexpr auto size() { return 1; }
171 inline const auto* data() const noexcept { return &t_; }
172 inline auto* data() noexcept { return &t_; }
173
174 private:
175 std::decay_t<C> t_;
176};
177} // namespace stan
178#endif
auto operator[](size_t i) const
Segfaults if out of bounds.
const value_type_t< C > * data() const noexcept
auto operator[](size_t i) const
Segfaults if out of bounds.
auto operator[](size_t i) const
Segfaults if out of bounds.
auto operator[](size_t i) const
Segfaults if out of bounds.
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
require_t< is_eigen_vector< std::decay_t< T > > > require_eigen_vector_t
Require type satisfies is_eigen_vector.
require_t< std::is_same< std::decay_t< T >, std::decay_t< S > > > require_same_t
Require types T and S satisfies std::is_same.
require_t< is_stan_scalar< std::decay_t< T > > > require_stan_scalar_t
Require type satisfies is_stan_scalar.
require_t< is_std_vector< std::decay_t< T > > > require_std_vector_t
Require type satisfies is_std_vector.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
require_t< is_var_matrix< std::decay_t< T > > > require_var_matrix_t
Require type satisfies is_var_matrix.
typename ref_type_if< true, T >::type ref_type_t
Definition ref_type.hpp:55
typename plain_type< std::decay_t< T > >::type plain_type_t
std::enable_if_t< Check::value > require_t
If condition is true, template is enabled.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
STL namespace.